[Haskell-beginners] Question: Data Type for user selection
Brent Yorgey
byorgey at seas.upenn.edu
Wed Aug 17 15:42:37 CEST 2011
On Tue, Aug 16, 2011 at 04:44:15PM +0200, Ertugrul Soeylemez wrote:
> Brent Yorgey <byorgey at seas.upenn.edu> wrote:
>
> > > That's a bit of a contradiction, because you are using existentials
> > > yourself in your GADT.
> >
> > No, he isn't.
> >
> > data BasicSelect a where
> > SelectionNum :: Num a => a -> BasicSelect a
> > SelectionStr :: Show a => a -> BasicSelect a
> >
> > 'a' shows up in the result type of both constructors, so there is no
> > existential quantification going on here.
>
> Oh, right. How would one express this as an ADT? Seems impossible to
> me.
You cannot, with just Haskell 2010. Strangely, if you try this:
data BasicSelect a = Num a => SelectionNum a
| Show a => SelectionStr a
you get this error (ghc 7.0.3):
Data constructor `SelectionNum' has existential type variables, or a
context
(Use -XExistentialQuantification or -XGADTs to allow this)
In the definition of data constructor `SelectionNum'
In the data type declaration for `BasicSelect'
And enabling ExistentialQuantification makes the error go away! So
apparently the ExistentialQuantification flag also enables type class
constraints on data constructors, even when no existential
quantification is involved. Odd.
-Brent
More information about the Beginners
mailing list