----------------------------------------------------------------------------- -- | -- Module : Generics.MultiRec.Rewriting -- Copyright : (c) 2008 Universiteit Utrecht -- License : BSD3 -- -- Maintainer : generics@haskell.org -- Stability : experimental -- Portability : non-portable -- -- By importing this module, the user is able to use all the rewriting -- machinery. The user is only required to provide an instance of -- @Ix@ for each datatype and @Rewrite@ for each system of datatypes. -- -- Consider a system of datatypes representing the abstract syntax tree -- of a simple language: -- -- @ -- data Expr = Const Int -- | Add Expr Expr -- | Mul Expr Expr -- | EVar Var -- | Let Decl Expr -- deriving Show -- -- data Decl = Var := Expr -- | Seq Decl Decl -- | None -- deriving Show -- -- type Var = String -- @ -- -- The instances of @Ix@ could be manually written (see examples/ASTUse.hs). -- Fortunately, there is some Template Haskell code to help generate them. -- The easiest way is then to write: -- -- @ -- data AST :: * -> * where -- Expr :: AST Expr -- Decl :: AST Decl -- Var :: AST Var -- -- $(deriveConstructors [''Expr, ''Decl, ''Var]) -- -- $(deriveSystem ''AST [''Expr, ''Decl, ''Var] "PFAST") -- type instance PF AST = PFAST -- @ -- -- Additionally, the instance @Rewrite@ would look like: -- -- @ -- instance Rewrite AST -- @ -- -- Build rules like this: -- -- @ -- inlineRule :: Var -> Expr -> RuleSpec Expr -- inlineRule var expr = Let (var := expr) (EVar var) :~> expr -- @ -- -- And apply them as follows: -- -- @ -- test :: Expr -- test = rewrite (rule Expr inlineRule) -- (Let ("x" := Mul (Const 6) (Const 9)) (EVar "x")) -- @ -- ----------------------------------------------------------------------------- module Generics.MultiRec.Rewriting ( module Generics.MultiRec.Rewriting.Rewriting , module Generics.MultiRec.Rewriting.Rules , module Generics.MultiRec.Rewriting.Strategies ) where import Generics.MultiRec.Rewriting.Rewriting import Generics.MultiRec.Rewriting.Rules import Generics.MultiRec.Rewriting.Strategies