[Haskell-beginners] How to avoid repeating a type restriction from a data constructor

Daniel Fischer daniel.is.fischer at googlemail.com
Thu Apr 25 12:06:36 CEST 2013


On Thursday 25 April 2013, 08:03:25, gs wrote:
> Daniel Fischer <daniel.is.fischer <at> googlemail.com> writes:
> > ...
> 
> You've mentioned GADT a few times, but I can't find a case where it's
> different to regular datatypes.
> 
> data Foo a = Eq a => Foo a
> 
> seems to have the same effect as
> 
> data Foo a where
>    Foo a :: Eq a => a -> Foo a
> 
> Both remember the Eq constraint if I pattern match on the constructor, and
> both ignore it otherwise.

Oy, sorry, I didn't look properly and moved the constraint before the datatype 
name (data Eq a => Foo a = Foo a) in my brain, which would be a datatype 
context.

The data Foo a = Eq a => Foo a syntax (requires ExistentialQuantification or 
GADTs) is indeed equivalent to the GADT syntax or existential quantification.

Oh well, at least the part explaining how that requires pattern matching to 
make the context available remains useful.



More information about the Beginners mailing list