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

AntC anthony_clayden at clear.net.nz
Thu Jul 18 12:33:13 CEST 2013

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?


More information about the Haskell-Cafe mailing list