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
signature.asc
Description: Digital signature
_______________________________________________ Haskell mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell
