RE: question re hugs and func dependencies
I replied last week: -----Original Message----- From: Simon Peyton-Jones Sent: 28 February 2001 16:51 To: 'Dominic Duggan'; hugs-bugs@haskell.org Subject: RE: please confirm that this is a feature 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: 02 March 2001 21:55 | To: haskell@haskell.org | Subject: question re hugs and func dependencies | | | Dear all, I haven't got a reply from hugs-bugs, | so I'll see if anyone here can answer the question. | | class foo a b | a |-> b where foo :: a -> b -> Int | instance foo Int Float where foo x y = 0 | instance foo [a] [b] where foo [x] [y] = foo x y | g x y = (foo [x] y) + (foo [y] x) | | It is my conjecture that Hugs terminates on type-checking | g because of a depth bound in the type-checker | (although there is no indication from the type-checker | that this is what is going on). | | Can anyone confirm or refute this conjecture? | | FWIW this is as part of the related work section | for a paper that has been accepted to JFP: | "Type-Checking Multi-Parameter Type Classes," | by D. Duggan and J. Ophel. | | I'd appreciate cc-ing any replies to me, I'm not | sure that I'm still on this mailing list. | | Cheers | --dd |
Simon thanks I'm afraid I didn't see your earlier reply. I didn't try this in GHC, thanks for the clarification. Hugs on the other hand does give a type: g :: (Foo [[[[a]]]] [[[[b]]]], Foo [[[[[b]]]]] [[[a]]]) => [[[[b]]]] -> [[[a]]] -> Int My assumption is that this is because of a depth bound check. As an editorial aside, it seems to me that the GHC approach of lazy context reduction introduces the same problems that functional dependencies were supposed to solve. The type of g with unresolved constraints hides a type error, and this is part of the motivation for FD given by Mark Jones in his web note. It seems to me that an approach of "I don't know" would be more useful, but I cc to the haskell list in case others have opinions. Cheers --dd
participants (2)
-
Dominic Duggan -
Simon Peyton-Jones