[Haskell-cafe] Is there already an abstraction for this?
sebf at informatik.uni-kiel.de
Mon Sep 22 22:39:30 EDT 2008
There are some approaches that support such generic transformations.
The simplest is probably Uniplate by Neil Mitchell:
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.
More information about the Haskell-Cafe