[Haskell-beginners] Question: Data Type for user selection
Brent Yorgey
byorgey at seas.upenn.edu
Tue Aug 16 16:29:51 CEST 2011
On Tue, Aug 16, 2011 at 09:54:52AM +0200, Ertugrul Soeylemez wrote:
> Brandon Allbery <allbery.b at gmail.com> wrote:
>
> > I think what you're reaching for here is a GADT:
> >
> > > data BasicSelect a where
> > > SelectionNum :: Num a => a -> BasicSelect a
> > > SelectionStr :: Show a => a -> BasicSelect a
> >
> > I think you otherwise end up with a typeclass or with existentials;
> > both introduce complexity, and I think the existentials solution still
> > allows anything to be stuffed into it, whereas you want to limit it to
> > SelectionNum or SelectionStr. (Typeclasses at least require an
> > instance to be defined first; but they don't prohibit people from
> > doing so, if that's what you're after.)
>
> 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.
-Brent
More information about the Beginners
mailing list