[Haskell-cafe] Which type variables are allowed in a context?

Claus Reinke claus.reinke at talk21.com
Sun May 31 05:58:20 EDT 2009


> --------------------------------------
> class A a where
>  foo :: A (b d) => a (c b)
> --------------------------------------
> 
> GHC compiles it successfully, but Hugs rejects it:
> 
> Ambiguous type signature in class declaration
> *** ambiguous type : (A a, A (b c)) => a (d b)
> *** assigned to    : foo

'd' ('c' in the error message) does not occur in any position that
would allow to determine it, so you'll have a hard time using 'foo'.
 
> What is the correct behavior, and which part of the haskell 98 report
> explains this?

4.3.4 Ambiguous Types, .. (?)

strictly speaking, that only rules out expressions of ambiguous
types, so GHC can defer complaining until you try to use 'foo',
and Hugs might give a dead code warning instead of an error,
but the late errors can be really confusing:

    Could not deduce (A (b d)) from the context (A (b d1)) ..

so GHC's no-error, no-warning approach for the class method
isn't optimal

Claus




More information about the Haskell-Cafe mailing list