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

2009-05-31 Thread Vladimir Reshetnikov
Hi,

Consider this (a bit pathological) Haskell code:

--
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

What is the correct behavior, and which part of the haskell 98 report
explains this?

Thanks,
Vladimir
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2009-05-31 Thread Claus Reinke

--
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


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