On 31-Aug-2000, William Lee Irwin III <[EMAIL PROTECTED]> wrote:
> {hugs} Example> :type cmethod . fromNat $ 1
> {hugs} cmethod . fromNat $ 1 :: (C a, Q a) => a
> 
> This is the expected typing, which I expect to be valid.
> 
> But the inferencer chokes on an actual binding like the following:
> x = cmethod . fromNat $ 1
> 
> Example> let x = cmethod . fromNat $ 1 in 0
> ERROR: Unresolved overloading
> *** Type       : (Q a, P a) => Integer
> *** Expression : let {...} in 0

You have run into the infamous monomorphism restriction.
Haskell 98 does not allow variables like `x' above to be polymorphic.
See section 4.5.5 in the Haskell report.  For more information,
try searching the archives of this mailing list for "monomorphism
restriction".

The error message that you get from Hugs could certainly be a lot
clearer than it is.

> For some reason, _explicitly_ typing it is okay.

Yes.  That's because of rule 1 (b) in 4.5.5.

Another work-around is to make `x' a function rather than a variable:

        let x _ = cmethod . fromNat $ 1 in 0

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to