[Haskell-cafe] Typeclass question

Luke Palmer lrpalmer at gmail.com
Sat Dec 27 14:49:22 EST 2008


On Sat, Dec 27, 2008 at 12:44 PM, David Menendez <dave at zednenem.com> wrote:

> On Sat, Dec 27, 2008 at 2:24 PM, Andrew Wagner <wagner.andrew at gmail.com>
> wrote:
> > I'm sure there's a way to do this, but it's escaping me at present. I
> want
> > to do something like this:
> >
> > data Foo = Bar a => Foo a Bool ...
> >
> > That is, I want to create a new type, Foo, whose constructor takes both a
> > Boolean and a value of a type of class Bar.
>
> Try this:
>
>    {-# LANGUAGE ExistentialQuantification #-}
>
>    data Foo = forall a. Bar a => Foo a Bool


Though for existentials, I find GADT more natural (actually I find GADT more
natural in most cases):

  data Foo where
      Foo :: Bar a => a -> Foo

Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081227/baef3522/attachment.htm


More information about the Haskell-Cafe mailing list