[Haskell] type class does not compile

Graham Klyne GK at ninebynine.org
Tue Jul 13 03:45:15 EDT 2004

At 19:24 12/07/04 -0500, Ben.Yu at combined.com wrote:
>please bear with me if my question turns out to be a stupid mistake. It has
>taken me hours to figure this out.
>class Rule r u u' m where
>   apply :: r -> u -> m u'
>data And = And
>data Bin a b o = Bin a b o
>instance (Monad m, Rule r1 u u' m, Rule r2 u' u'' m) => Rule (Bin r1 r2
>And) u u'' m where
>   apply (Bin r1 r2 _) u = apply r1 u >>= apply r2
>Ghc complains about "Could not deduce (Rule r1 u u'1 m, Rule r2 u'1 u''
>m)", but it is obviously same as the constraint I gave in the instance
>What am I doing wrong here?

There's no information in the instance type for the compiler to figure out 
what u' (in the constraint expressions) might be.  (See other responses.)


I would question whether or not you really should be using a type class 
here -- that depends on your application, but I've done some work involving 
simple inference rules and found that a polymorphic algebraic datatype 
(with function-valued members) served my purposes better than a type class.


>Thank you very much!
>This message is intended only for the addressee and may contain information
>that is confidential or privileged. Unauthorized use is strictly prohibited
>and may be unlawful. If you are not the intended recipient, or the person
>responsible for delivering to the intended recipient, you should not read,
>copy, disclose or otherwise use this message, except for the purpose of
>delivery to the addressee. If you have received this email in error, please
>delete and advise us immediately.
>Haskell mailing list
>Haskell at haskell.org

Graham Klyne
For email:

More information about the Haskell mailing list