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
- module Data.Generics.Biplate
- class PlateAll from to where
- plateAll :: from -> Type from to
- class PlateOne to where
- plateOne :: to -> Type to to
- 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
This class is for when the target and container are the same type.
The Combinators
plate :: from -> Type from toSource
The main combinator used to start the chain.
The following rule can be used for optimisation:
plate Ctor |- x == plate (Ctor x)
(|+) :: PlateAll item to => Type (item -> from) to -> item -> Type from toSource
The field to the right may contain the target.
(|-) :: Type (item -> from) to -> item -> Type from toSource
The field to the right does not contain the target.