[Haskell-cafe] Type families and polymorphism
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Sun Jul 12 05:03:35 EDT 2009
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
More information about the Haskell-Cafe
mailing list