Hi Jeremy,
There are some approaches that support such generic transformations.
The simplest is probably Uniplate by Neil Mitchell:
http://www-users.cs.york.ac.uk/~ndm/uniplate/
The function 'rewrite' is what you are looking for. If you change the
definition of 'identity' to:
identity (Sum (Lit 0) a) = Just a
identity (Sum a (Lit 0)) = Just a
identity (Difference a (Lit 0)) = Just a
identity (Product a (Lit 1)) = Just a
identity (Product (Lit 1) a) = Just a
identity (Quotient a (Lit 1)) = Just a
identity _ = Nothing
then the function 'rewrite identity :: Expr -> Expr' does what you want.
Cheers,
Sebastian
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe