|
| Data.Generics.PlateDirect |
|
|
|
|
| Description |
This module supplies a method for writing Biplate instances more easily.
This module requires fewest extensions, highest performance, and most instance
definitions.
To take an example:
data Expr = Var Int | Pos Expr String | Neg Expr | Add Expr Expr
data Stmt = Seq [Stmt] | Sel [Expr] | Let String Expr
instance PlateOne Expr where
plateOne (Var x ) = plate Var |- x
plateOne (Pos x y) = plate Pos |* x |- y
plateOne (Neg x ) = plate Neg |* x
plateOne (Add x y) = plate Add |* x |* y
instance PlateAll Expr Expr where
plateAll = plateSelf
instance PlateOne Stmt where
plateOne (Seq x ) = plate Seq ||* x
plateOne (Sel x ) = plate Sel ||+ x
plateOne (Let x y) = plate Let |- x |- y
instance PlateAll Stmt Stmt where
plateAll = plateSelf
instance PlateAll Stmt Expr where
plateAll (Seq x ) = plate Seq ||+ x
plateAll (Sel x ) = plate Sel ||* x
plateAll (Let x y) = plate Let |- x |* y
|
|
| Synopsis |
|
| module Data.Generics.Biplate | | | class PlateAll from to where | | | | class PlateOne to where | | | | plate :: from -> Type from to | | | plateSelf :: to -> Type to to | | | (|+) :: PlateAll item to => Type (item -> from) to -> item -> Type from to | | | (|-) :: Type (item -> from) to -> item -> Type from to | | | (|*) :: Type (to -> from) to -> to -> Type from to | | | (||+) :: PlateAll item to => Type ([item] -> from) to -> [item] -> Type from to | | | (||*) :: Type ([to] -> from) to -> [to] -> Type from to |
|
|
| Documentation |
|
| module Data.Generics.Biplate |
|
| The Classes
|
|
| class PlateAll from to where |
This class represents going from the container type to the target.
If from == to then use plateSelf, otherwise use plate and the
other combinators.
| | | Methods | | plateAll :: from -> Type from to |
|
|
|
| class PlateOne to where |
| This class is for when the target and container are the same type.
| | | Methods | | plateOne :: to -> Type to to |
|
|
|
| The Combinators
|
|
| plate :: from -> Type from to |
The main combinator used to start the chain.
The following rule can be used for optimisation:
plate Ctor |- x == plate (Ctor x)
|
|
| plateSelf :: to -> Type to to |
| Used for PlayAll definitions where both types are the same.
|
|
| (|+) :: PlateAll item to => Type (item -> from) to -> item -> Type from to |
| The field to the right may contain the target.
|
|
| (|-) :: Type (item -> from) to -> item -> Type from to |
| The field to the right does not contain the target.
|
|
| (|*) :: Type (to -> from) to -> to -> Type from to |
| The field to the right is the target.
|
|
| (||+) :: PlateAll item to => Type ([item] -> from) to -> [item] -> Type from to |
| The field to the right is a list of types which may contain the target
|
|
| (||*) :: Type ([to] -> from) to -> [to] -> Type from to |
| The field to the right is a list of the type of the target
|
|
| Produced by Haddock version 0.8 |