please confirm that this is a feature

Simon Peyton-Jones simonpj@microsoft.com
Wed, 28 Feb 2001 08:50:35 -0800


GHC infers the type

  g :: (Foo [[a]] [b], Foo [[b]] [a]) => [a] -> [b] -> Int

As you imply, if GHC used the instance decl to simplify
the first constraint to Foo [a] b, for example, then the functional
dependency would kick in, and there would be an infinite loop.
But GHC's constraint simplification is (now) lazy, unless forced
to be eager by supplying a type signature.

I think Hugs is the same, and I think that's probably why it
terminates.

Interesting example!

Simon

| -----Original Message-----
| From: Dominic Duggan [mailto:dduggan@cs.stevens-tech.edu]
| Sent: 28 February 2001 16:00
| To: hugs-bugs@haskell.org
| Subject: please confirm that this is a feature
| 
| 
| I am finishing up revisions on a paper that
| has been accepted to JFP, on type-checking
| with multi-parameter type classes.
| With the following definitions:
| 
| | class Foo a b | a -> b where foo :: a -> b -> Int
| |
| | instance Foo Int Float where foo x y = 0
| |
| | instance Foo a b => Foo [a] [b] where foo [x] [y] = foo x y
| |
| | g x y = (foo [x] y) + (foo [y] x)
| 
| In our system type-checking fails to terminate when
| type-checking "g", but Hugs 98 (Feb 2001) returns
| a type.
| 
| I assume that this is because of a depth bound in the
| type-checker, can you confirm this before I submit
| the final version of the paper?
| 
| Thanks
| --dd
|