[Haskell] type class does not compile

Martin Sulzmann sulzmann at comp.nus.edu.sg
Mon Jul 12 20:56:33 EDT 2004


Another solution would be to use lexically scoped type variables:

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)::m u') >>= apply r2

Martin


 > Hi,
 > 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
 > declaration.
 > 
 > What am I doing wrong here?
 > 
 > 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
 > http://www.haskell.org/mailman/listinfo/haskell


More information about the Haskell mailing list