class hierarchies inmature in hugs

Ralf Laemmel
Thu, 07 Mar 2002 10:27:20 +0100

I just saw someone "misusing"
for bug reports. I am going to join especially
- it is a funny one,
- the bug hasn't been fixed since Sep. 2001,
- it is not even put in the list of known bugs since then.


The following code works with ghc but not with hugs
(incl. Dec. 2001 release)

import Monad

class Monad m => C1 m x

-- Monad m is implied by C1 but test diverges if constraint not present

class (C1 m x) => C2 m x
    c2 :: x -> m x

instance Monad m => C1 m Bool
instance C2 Maybe Bool
    c2 = return

test :: Maybe Bool
test = c2 True


So you see, C1 is a kind of derived from Monad.
C2 is derived from C1 and hence implicitly from Monad.
This is a kind of minimal example.

Just attempt to evaluate "test".
hugs will loop.
There is a way to help hugs.
Add Monad m as a further class constraint to C2.
Then it will work.
Please note both programs do type check,
and this is in fact fine.

More generally, I get these looping programs
whenever I have non-trivial class hierarchies
with three or more layers.

I guess more people should have suffered from that?


Dr.-Ing. Ralf Laemmel
CWI & VU, Amsterdam, The Netherlands