Why are field selectors functions? [was: ghc-users A possible alternative to dot notation for record access]

No! This isn't more bikeshedding about notation. It's a bit of Haskell archaeology.
On Sun, Jun 30, 2013 at 2:59 AM, Judah Jacobson wrote: [This isn't exactly what Judah wrote.] ...
Instead of `x f` (to access field x of record f), maybe we could write `f{x}` as the record selection.
The more I thought about that ... We use { ... } to declare records, build them, update them. We use { ... } in pattern matching to access named fields. Why don't we use { ... } to access named fields in terms? The syntax `e{ foo }` is unused in H98. (Or at least it was in 1998.) Can someone who was there at the time (1994?, TRex?) remember if that was ever considered? In the declaration, the build/update, and pattern match: data R = MkR { foo :: Int } r = MkR { foo = 7 } \ (MkFoo { foo }) -> ... -- using NamedFieldPuns `foo` is clearly bound to an Int. So why is there this `foo` thing that isn't an Int? AntC

AntC
No! This isn't more bikeshedding about notation.
It's a bit of Haskell archaeology.
On Sun, Jun 30, 2013 at 2:59 AM, Judah Jacobson wrote: [This isn't exactly what Judah wrote.] ...
Instead of `x f` (to access field x of record f), maybe we could write `f{x}` as the record selection.
The more I thought about that ...
We use { ... } to declare records, build them, update them. We use { ... } in pattern matching to access named fields.
Why don't we use { ... } to access named fields in terms?
The syntax `e{ foo }` is unused in H98. (Or at least it was in 1998.) Can someone who was there at the time (1994?, TRex?) remember if that was ever considered?
No one else has answered (at least in café), but perhaps the reason is that like me they can’t really remember! I do remember that since Haskell is a functional language we wanted as many things to be functions as possible; we did want to be able to pass field selectors around as arguments to other functions. I vaguely remember suggesting some years later that we should have {…} being a function, so that {field} is a field selector and {field=value} is a field setter (and requiring that you had to write use normal function application: “{field} structure” to select field from structure). SimonPJ gave a reason why not, and I’m sure it will be possible to search out what he said. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk
participants (2)
-
AntC
-
Jon Fairbairn