fixplate-0.1.1: Uniplate-style generic traversals for fixed-point types, with some extras.

Data.Generics.Fixplate.Traversals

Contents

Description

Uniplate-style traversals.

Synopsis

Queries

children :: Foldable f => Mu f -> [Mu f]Source

The list of direct descendants.

universe :: Foldable f => Mu f -> [Mu f]Source

The list of all substructures. Together with list-comprehension syntax this is a powerful query tool. For example the following is how you get the list of all variable names in an expression:

 variables expr = [ s | Fix (Var s) <- universe expr ]

Traversals

transform :: Functor f => (Mu f -> Mu f) -> Mu f -> Mu fSource

Bottom-up transformation.

transformM :: (Traversable f, Monad m) => (Mu f -> m (Mu f)) -> Mu f -> m (Mu f)Source

topDownTransform :: Functor f => (Mu f -> Mu f) -> Mu f -> Mu fSource

Top-down transformation. This provided only for completeness; usually, it is transform what you want use instead.

topDownTransformM :: (Traversable f, Monad m) => (Mu f -> m (Mu f)) -> Mu f -> m (Mu f)Source

descend :: Functor f => (Mu f -> Mu f) -> Mu f -> Mu fSource

Non-recursive top-down transformation.

descendM :: (Traversable f, Monad m) => (Mu f -> m (Mu f)) -> Mu f -> m (Mu f)Source

rewrite :: Functor f => (Mu f -> Maybe (Mu f)) -> Mu f -> Mu fSource

Bottom-up transformation until a normal form is reached.

rewriteM :: (Traversable f, Monad m) => (Mu f -> m (Maybe (Mu f))) -> Mu f -> m (Mu f)Source

Context

context :: Traversable f => Mu f -> Attr f (Mu f -> Mu f)Source

We annotate the nodes of the tree with functions which replace that particular subtree.

contextList :: Traversable f => Mu f -> [(Mu f, Mu f -> Mu f)]Source

Flattened version of context.

Folds

foldLeft :: Foldable f => (a -> Mu f -> a) -> a -> Mu f -> aSource

(Strict) left fold. Since Mu f is not a functor, but a data type, we cannot make it an instance of the Foldable type class.

foldLeftLazy :: Foldable f => (a -> Mu f -> a) -> a -> Mu f -> aSource

foldRight :: Foldable f => (Mu f -> a -> a) -> a -> Mu f -> aSource