transformations- Generic representation of tree transformations

Safe HaskellNone




deriveRefRep :: Name -> (Name -> Name) -> Q [Dec]Source

Derive data type with references and HasRef instance. For a data type N the name of the constructor for a reference is RefN, and the given function is used to change the rest of the constructors and the data type name itself. For example, for the following definition:

 data Tree = Leaf Int | Bin Tree Tree
 data TreeAST :: * -> * where
    Tree :: TreeAST Tree
 $(deriveRefRep ''TreeAST (postfix "R"))

The following data type is generated:

 data TreeR = LeafR Int | BinR TreeR TreeR | RefTree Path
 instance HasRef TreeAST