GHC bug,or Hugs feature?

Arthur Baars arthurb@cs.uu.nl
Wed, 07 Aug 2002 14:36:42 +0200


One of our students had a program that successfully compiled with Hugs but
failed to type check in GHC. After adding some type signatures GHC could
compile the program as well.

The definitions below are not supposed to make sense, (f and g are just
identity functions) but illustrate the situation in the students code:
1) the functions f and g are mutually recursive
2) there is a sort of (indirect) polymorphic recursion
   - the polymorphic types of f and g are instantiated to (Char->Char)

f :: a -> a
f a | True         = a
    | g 'a' == 'a' = g a

g :: a -> a
g a | True         = a
    | f 'a' == 'a' = f a

The code above is successfully type-checked by both Hugs and GHC.
If we remove either the type signature of f or the type signature of g,
however, GHC fails to type check the code. Hugs still infers: f,g :: a->a
When removing both type signatures GHC and Hugs both infer f,g::Char->Char,
as expected.

So this code failed in GHC:

f :: a -> a
f a | True         = a
    | g 'a' == 'a' = g a

g a | True         = a
    | f 'a' == 'a' = f a

Is this a bug in GHC or a feature of Hugs?
I did not check what NHC and other Haskell compilers say about this. Can
someone try?

Cheers,
Arthur