Records (was Re: [Haskell] Improvements to GHC)

David Roundy droundy at abridgegame.org
Sun Nov 20 14:09:04 EST 2005


On Sun, Nov 20, 2005 at 03:43:08PM +0100, Tomasz Zielonka wrote:
> On Sun, Nov 20, 2005 at 08:54:35AM -0500, David Roundy wrote:
> > As an aside, what's responsible for the insanity of pattern matching
> > record fields being backwards? I'd bar = b to bind b to bar, not the
> > other way around... why should record pattern matching use '=' in a
> > manner opposite from the rest of Haskell?
> 
> It just mimics the way (record) values are constructed, as in all
> pattern matching in Haskell. You can put a pattern variable everywhere
> you could put a value in a corresponding constructing expression. For
> example, all these "terms" can be used both as an expression and a
> pattern. In the first case x, y, z are expressions, in the second they
> are patterns.
> 
>     [x,y,z]
[...]
>     R { field1 = x, field2 = y, field3 = z }
> 
> I think this is very consistent.

I see, you're right that it's consistent, but I still don't like the use of
'=' in this scenario.  I don't really have a better idea, but something
like

    R { field1 -:- x, field2 -:- y, field3 -:- z }

(where I don't like the -:- but can't think of anything better off the top
of my head) might be more intuitive, since '=' means bind the value on the
right to the name on the left everywhere else in haskell, but in record
syntax it's part of a constructor.  It'd be nice to reuse an existing
haskell syntax ("->" ?), but I can't think of one that would fit.  One
could perhaps use :=, which at least looks like a constructor rather than a
binding...
-- 
David Roundy
http://www.darcs.net


More information about the Haskell mailing list