GHC bug,or Hugs feature?

Arthur Baars arthurb@cs.uu.nl
Wed, 07 Aug 2002 15:34:11 +0200


In Mark Jones' paper Typing Haskell in Haskell, I found the following
example(in the section on binding-groups):

f   :: Eq a => a -> Bool
f x = x==x || g True
g y = y<=y || f True

According to the paper the inferred type of g should be:
 g::Ord a => a -> Bool

Hugs infers this type but GHC infers the following *ambiguous* type:
*Main> :i g
-- g is a variable, defined at Test.hs:25
g :: forall a. (Eq a) => Bool -> Bool

When adding an explicit type signature for g, Hugs happily accepts the code,
but GHC gives the following error:

f   :: Eq a => a -> Bool
f x = x==x || g True
g   :: Ord a => a -> Bool
g y = y<=y || f True

Test.hs:24:
    Couldn't match `{Ord a}' against `{Eq a1}'
    When matching the contexts of the signatures for
      g :: forall a. (Ord a) => a -> Bool
      f :: forall a. (Eq a) => a -> Bool
    The signature contexts in a mutually recursive group should all be
identical
    When generalising the type(s) for g, f
Failed, modules loaded: none.

I think the problems are caused by differences in the binding group analysis
in Hugs and GHC. 

Malcolm, could you check what NHC says about the examples above?

Cheers, 
 Arthur