Jeremy Yallop wrote:
> Why does compiling the following program give an error?
>
>> {-# LANGUAGE TypeFamilies, RankNTypes #-}
>>
>> type family TF a
>>
>> identity :: (forall a. TF a) -> (forall a. TF a)
>> identity x = x
>
> GHC 6.10.3 gives me:
>
>     Couldn't match expected type `TF a1' against inferred type `TF a'
>     In the expression: x
>     In the definition of `identity': identity x = x

The error message is slightly better in GHC head:

    Couldn't match expected type `TF a1' against inferred type `TF a'
      NB: `TF' is a type function, and may not be injective
    In the expression: x
    In the definition of `identity': identity x = x

Dan Doel already explained how the lack of injectivity leads to a type
checking error.

FWIW, the same code would work with a data family, because data families
are injective.

regards,

Bertram
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to