[Haskell-cafe] Different behavior of GHC 6.10.1 and Hugs (Sep 2006)

Daniel Fischer daniel.is.fischer at web.de
Sat Apr 3 10:06:44 EDT 2010


Am Samstag 03 April 2010 15:40:03 schrieb Vladimir Reshetnikov:
> Hi list,
>
> GHC 6.10.1:
>
> Prelude> :t let f x y = return x == return y in f
> let f x y = return x == return y in f :: (Eq (m a), Monad m) => a -> a
> -> Bool
>
> Hugs (Sep 2006):
>
> Hugs> :t let f x y = return x == return y in f
> ERROR - Ambiguous type signature in inferred type
> *** ambiguous type : (Eq (a b), Monad a) => b -> b -> Bool
> *** assigned to    : f
>
> Who is right?

I think hugs is righter. GHC lets you define f, but you can't use it; if 
you try, you'll get

    No instance for (Eq (m Bool))
      arising from a use of `f' at TypeTest.hs:5:6-17
    Possible fix: add an instance declaration for (Eq (m Bool))
    In the expression: f True False
    In the definition of `res': res = f True False

and if you provide e.g.

instance (Monad m) => Eq (m Bool) where
    _ == _ = False

, you'll get

    Ambiguous type variable `m' in the constraint:
      `Monad m' arising from a use of `f' at <interactive>:1:0-11
    Probable fix: add a type signature that fixes these type variable(s)


The only difference is that GHC fails more lazily for such ambiguous types. 
than hugs.

I think, according to http://haskell.org/onlinereport/decls.html#sect4.3.4 
, GHC also should fail on the definition and not only on use.

>
> --
> Thanks
> Vladimir



More information about the Haskell-Cafe mailing list