[Haskell-cafe] question about GADT and deriving automatically a Show instance

Chris Wong chrisyco+haskell-cafe at gmail.com
Sat May 18 00:28:57 CEST 2013


On Sat, May 18, 2013 at 9:11 AM, TP <paratribulations at free.fr> wrote:
>
> So the following version does not work:
> ----------------------------------------
> [..]
> data Person :: Gender -> * where
>     Dead :: Person Gender  -- WHAT DO I PUT HERE
>     Alive :: { name :: String
>               , weight :: Float
>               , father :: Person Gender } -> Person Gender

Here's the problem. In the line:

    Dead :: Person Gender

you are referring to the Gender *type*, not the Gender kind.

To refer to the kind instead, change this to:

    Dead :: forall (a :: Gender). Person a

This means "for all types A which have the kind Gender, I can give you
a Person with that type." The Alive declaration and deriving clause
can be fixed in a similar way.

Also, to enable the "forall" syntax, you need to add

    {-# LANGUAGE ExplicitForAll #-}

at the top of the file.

Chris


--
Chris Wong, fixpoint conjurer
  e: lambda.fairy at gmail.com
  w: http://lfairy.github.io/



More information about the Haskell-Cafe mailing list