Hello, I have encountered a type error that I find quite puzzling. I would appreciate it if someone could help me understand what is going wrong. Here is the program:
data Expr = Var String | Const Int data Constraint = Zero Expr | AndL Constraint
class AbSyn a where subst :: Expr -> String -> a -> a
instance AbSyn Expr where subst e n expr = expr
instance AbSyn Constraint where subst e n constr = let sub = subst e n -- :: AbSyn a => a -> a in case constr of Zero expr -> Zero (sub expr) AndL cs -> AndL (sub cs)
GHC 6.4 (as well as Hugs March 2005) produces this error: Couldn't match `Constraint' against `Expr' Expected type: Constraint Inferred type: Expr In the application `sub cs' In the first argument of `AndL', namely `(sub cs)' If I replace the last line with this one, everything is fine: AndL cs -> AndL (subst e n cs) It looks sort of like sub is being monomorphised -- or something? Thanks for having a look, Paul