
2 Dec
2013
2 Dec
'13
8:48 a.m.
class FooClass a where foo1 :: a -> a foo2 :: a -> a
instance FooClass Integer where
foo1 v = 1 foo2 v = 2
data Bar = Bar1 Integer | Exp1 Bar Bar | Exp2 Bar Bar deriving Show
instance FooClass Bar where
foo1 b = case b of Bar1 i -> Bar1 (foo1 i) Exp1 b1 b2 -> Exp1 (foo1 b1) (foo1 b2) Exp2 b1 b2 -> Exp2 (foo1 b1) (foo1 b2)
foo2 b = case b of Bar1 i -> Bar1 (foo2 i) Exp1 b1 b2 -> Exp1 (foo2 b1) (foo2 b2) Exp2 b1 b2 -> Exp2 (foo2 b1) (foo2 b2)
I think you're really asking for a generics library like 'uniplate': http://community.haskell.org/~ndm/darcs/uniplate/uniplate.htm Greetings, Daniel