[Haskell-cafe] Type families versus functional dependencies
question
Manuel M T Chakravarty
chak at cse.unsw.edu.au
Thu Jul 3 23:03:00 EDT 2008
Alexey Rodriguez:
> We are having trouble with the following program that uses type
> families:
>
> > class Blah f a where
> > blah :: a -> T f f a
>
> > class A f where
> > type T f :: (* -> *) -> * -> *
>
> the following function does not type:
>
> > wrapper :: forall a f . Blah f a => a -> T f f a
> > wrapper x = blah x
>
> GHC gives the error:
>
> Couldn't match expected type `T f1 f1 a'
> against inferred type `T f f a'
> In the expression: blah x
> In the definition of `wrapper': wrapper x = blah x
>
> Maybe it is a problem with ambiguous types, namely "f" appears only
> in applications of "T". But that is not the case, there is a "naked"
> f appearing as the argument of "T f". But perhaps the type checker
> does not want to unify those two f's precisely because they are the
> arguments of "T f".
The problem is that blah's type is ambiguous, as f does only occur as
an argument to the type family. If you'd define
class Blah f a where
blah :: a -> f -> T f f a
(and change the rest of the program accordingly) then all will be
fine. See this thread for a more in-depth discussion of the problem:
http://www.haskell.org/pipermail/haskell-cafe/2008-April/041385.html
Manuel
More information about the Haskell-Cafe
mailing list