Hi,
I've come accross an interesting bit of code:
============================================================================
class X a where
u :: a b -> a b
f :: X a => b -> a b
f = f
g :: X a => a b -> b
g = g
-- h :: X a => b -> a c
h b = f (g (h b))
==============================================================================
Hugs admits the script as it is. When asked for the type of h, it says:
Main> :t h
h :: X a => b -> a c
But, when you add the type of h to the script (i.e. uncomment the
type declaration for h), it says:
Type checking
ERROR "a.hs" (line 11): Cannot justify constraints in explicitly typed binding
*** Expression : h
*** Type : X a => b -> a c
*** Given context : X a
*** Constraints : X d
Looks like polymorphic recursion in the presence of type classes confuses the
type checker (?)
This is interesting since if I tell tell the system what it can deduce, it gets
confused. GHC behaves similarly, so I suspect this is a Haskell problem, rather
than a particular implementation. Any comments?
-Levent.