[Haskell] (small) records proposal for Haskell '06

Dylan Thurston dthurston at barnard.edu
Tue Jan 3 20:25:01 EST 2006


On Mon, Jan 02, 2006 at 08:43:56AM -0500, David Roundy wrote:
> data FooBar = Foo { foo :: Int } | FooBar = { foo :: Int, bar :: Int }
> 
> desugars to something like
> 
> data FooBar = Foo Int | FooBar Int Int
> 
> foo :: FooBar -> Int
> foo (Foo f) = f
> foo (FooBar f _) = f
> bar :: FooBar -> Int
> bar (Foo _) = error "bad Foo"
> bar (FooBar _ b) = b

I'm sure you know this, but I want to be explicit for everyone: If you
keep the pattern-matching syntax, this could be coded more elegantly
by hand, without counting positions in a record, by

data FooBar = Foo { foo :: Int } | FooBar = { foo :: Int, bar :: Int }

foo :: FooBar -> Int
foo (Foo { foo = f }) = f
foo (FooBar { foo = f}) = f
bar :: FooBar -> Int
bar (Foo _) = error "bad Foo"
bar (FooBar { bar = f}) = f

I think this proposal is great.

Peace,
	Dylan
-------------- 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/20060103/8d496312/attachment-0001.bin


More information about the Haskell mailing list