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

Safe HaskellNone



This module defines Uniplate / Biplate instances for every type with a Data instance. Using GHC, Data can be derived automatically with:

 data Expr = Var Int | Neg Expr | Add Expr Expr
             deriving (Data,Typeable)

All the Uniplate operations defined in Data.Generics.Uniplate.Operations can be used. If you are working with abstract data types, such as Map or Set from the containers package, you may also need to use the data types defined in Data.Generics.Uniplate.Data.Instances.

For faster performance (5x faster, but requires writing instances) switch to Data.Generics.Uniplate.Direct. If you get instance conflicts when using both Data and Direct, switch to Data.Generics.Uniplate.DataOnly.

The instances are faster than GHC because they precompute a table of useful information, then use this information when performing the traversals. Sometimes it is not possible to compute the table, in which case this library will perform about the same speed as SYB.

Setting the environment variable $UNIPLATE_VERBOSE has the following effects:

  • -1 - raise a program error every time construction of the table fails
  • 0 (or unset) - never print any messages or raise any errors
  • 1 - give a message every time a table is computed
  • 2 - give a message when table computation fails

The $UNIPLATE_VERBOSE environment variable must be set before the first call to uniplate.



transformBis :: forall a. Data a => [[Transformer]] -> a -> aSource

Apply a sequence of transformations in order. This function obeys the equivalence:

 transformBis [[transformer f],[transformer g],...] == transformBi f . transformBi g . ...

Each item of type [Transformer] is applied in turn, right to left. Within each [Transformer], the individual Transformer values may be interleaved.

The implementation will attempt to perform fusion, and avoid walking any part of the data structure more than necessary. To further improve performance, you may wish to partially apply the first argument, which will calculate information about the relationship between the transformations.

transformer :: Data a => (a -> a) -> TransformerSource

Wrap up a (a -> a) transformation function, to use with transformBis