Records (was Re: [Haskell] Improvements to GHC)
David Roundy
droundy at abridgegame.org
Sun Nov 20 08:54:35 EST 2005
On Sun, Nov 20, 2005 at 01:40:01PM +0100, Georg Martius wrote:
> 7. Unordered records.
> I don' t understand it.
It's just that I'd like to be able to write:
data FooBar = FooBar { foo, bar :: String }
such that you can't write
let f = FooBar "a" "b"
but instead are forced to write
let f = FooBar { foo = "a", bar = "b" }
More importantly when you pattern match, you couldn't write
case f of FooBar _ b -> b
but instead would have to write
case f of FooBar { bar = b } -> b
The reason being that I'd like to be able to export constructors from a
module in such a way that I can later reorder or add or remove field from
that record without breaking any pattern-matching code, and if I'm only
reordering the fields, I shouldn't break any constructor code either.
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?
--
David Roundy
http://www.darcs.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell/attachments/20051120/a4775f8b/attachment.bin
More information about the Haskell
mailing list