Search code examples
haskellsyntaxgadt

Are type variables in GADT heads meaningful?


Is there a difference between these two GADT declarations?

data A a b where
    ...

data A :: * -> * -> * where
    ...

Solution

  • There is no difference. One might think that not mentioning the type variables in the header would be needed to use different names for them in the constructor signatures, as in:

    data A :: * -> * -> * where
        AN :: Num x => x -> b -> A x b
        AS :: IsString s => s -> b -> A s b
    

    However, as the GHC Users Guide says...

    Unlike a Haskell-98-style data type declaration, the type variable(s) in the data Set a where header have no scope.

    ... and so this also works:

    data A a b where
        AN :: Num x => x -> b -> A x b
        AS :: IsString s => s -> b -> A s b