uniplate-1.0.1: Uniform type generic traversals.

Data.Generics.PlateDirect

Contents

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

Documentation

The Classes

class PlateAll from to whereSource

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 toSource

class PlateOne to whereSource

This class is for when the target and container are the same type.

Methods

plateOne :: to -> Type to toSource

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)

plateSelf :: to -> Type to toSource

Used for PlayAll definitions where both types are the same.

(|+) :: 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.

(|*) :: Type (to -> from) to -> to -> Type from toSource

The field to the right is the target.

(||+) :: PlateAll item to => Type ([item] -> from) to -> [item] -> Type from toSource

The field to the right is a list of types which may contain the target

(||*) :: Type ([to] -> from) to -> [to] -> Type from toSource

The field to the right is a list of the type of the target