uniplate-1.6.12: Help writing simple, concise and fast generic operations.

Safe HaskellNone

Data.Generics.Uniplate.Typeable

Contents

Description

RECOMMENDATION: Use Data.Generics.Uniplate.Data instead - it usually performs faster (sometimes significantly so) and requires no special instance declarations.

This module supplies a method for writing Uniplate / Biplate instances. One instance declaration is required for each data type you wish to work with. The instances can be generated using Derive: http://community.haskell.org/~ndm/derive/.

To take an example:

 data Expr = Var Int | Neg Expr | Add Expr Expr
             deriving Typeable

 instance (Typeable a, Uniplate a) => PlateAll Expr a where
     plateAll (Var x  ) = plate Var |+ x
     plateAll (Neg x  ) = plate Neg |+ x
     plateAll (Add x y) = plate Add |+ x |+ y

Synopsis

Documentation

The Class

class PlateAll from to whereSource

This class should be defined for each data type of interest.

Methods

plateAll :: from -> Type from toSource

This method should be defined using plate and |+, |-.

Instances

PlateAll Bool to 
PlateAll Char to 
PlateAll Double to 
PlateAll Float to 
PlateAll Int to 
PlateAll Integer to 
PlateAll () to 
(PlateAll from to, Typeable from, Typeable to, Uniplate to) => PlateAll [from] to 
(Integral a, PlateAll a to, Typeable a, Typeable to, Uniplate to) => PlateAll (Ratio a) to 
(PlateAll from to, Typeable from, Typeable to, Uniplate to) => PlateAll (Maybe from) to 
(PlateAll a to, Typeable a, PlateAll b to, Typeable b, Typeable to, Uniplate to) => PlateAll (Either a b) to 
(PlateAll a to, Typeable a, PlateAll b to, Typeable b, Typeable to, Uniplate to) => PlateAll (a, b) to 
(PlateAll a to, Typeable a, PlateAll b to, Typeable b, PlateAll c to, Typeable c, Typeable to, Uniplate to) => PlateAll (a, b, c) to 
(PlateAll a to, Typeable a, PlateAll b to, Typeable b, PlateAll c to, Typeable c, PlateAll d to, Typeable d, Typeable to, Uniplate to) => PlateAll (a, b, c, d) to 
(PlateAll a to, Typeable a, PlateAll b to, Typeable b, PlateAll c to, Typeable c, PlateAll d to, Typeable d, PlateAll e to, Typeable e, Typeable to, Uniplate to) => PlateAll (a, b, c, d, e) to 

The Combinators

plate :: from -> Type from toSource

The main combinator used to start the chain.

(|+) :: (Typeable item, Typeable to, 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. This can be used as either an optimisation, or more commonly for excluding primitives such as Int.

plateProject :: (Typeable item, Typeable to, PlateAll item to) => (from -> item) -> (item -> from) -> from -> Type from toSource

Write an instance in terms of a projection/injection pair. Usually used to define instances for abstract containers such as Map:

 instance (Ord a, Typeable a, PlateAll a c, Typeable b, PlateAll b c,
          Typeable c, PlateAll c c) => PlateAll (Map.Map a b) c where
     plateAll = plateProject Map.toList Map.fromList