Copyright | (c) 2011 Patrick Bahr |
---|---|
License | BSD3 |
Maintainer | Patrick Bahr <paba@diku.dk> |
Stability | experimental |
Portability | non-portable (GHC Extensions) |
Safe Haskell | None |
Language | Haskell98 |
This module defines type generic functions and recursive schemes along the lines of the Uniplate library. All definitions are generalised versions of those in Data.Comp.Generic.
Synopsis
- subterms :: forall f. HFoldable f => HFix f :=> [E (HFix f)]
- subterms' :: forall f g. (HFoldable f, g :<: f) => HFix f :=> [E (g (HFix f))]
- transform :: forall f. HFunctor f => (HFix f :-> HFix f) -> HFix f :-> HFix f
- transformM :: forall f m. (HTraversable f, Monad m) => NatM m (HFix f) (HFix f) -> NatM m (HFix f) (HFix f)
- query :: HFoldable f => (HFix f :=> r) -> (r -> r -> r) -> HFix f :=> r
- subs :: HFoldable f => HFix f :=> [E (HFix f)]
- subs' :: (HFoldable f, g :<: f) => HFix f :=> [E (g (HFix f))]
- size :: HFoldable f => Cxt h f a :=> Int
- depth :: HFoldable f => Cxt h f a :=> Int
Documentation
subterms :: forall f. HFoldable f => HFix f :=> [E (HFix f)] Source #
This function returns a list of all subterms of the given
term. This function is similar to Uniplate's universe
function.
subterms' :: forall f g. (HFoldable f, g :<: f) => HFix f :=> [E (g (HFix f))] Source #
This function returns a list of all subterms of the given term that are constructed from a particular functor.
transform :: forall f. HFunctor f => (HFix f :-> HFix f) -> HFix f :-> HFix f Source #
transform :: (forall i. Term fs i -> Term fs i) -> Term f l -> Term f l
If f :: Term fs i -> Term fs i
rewrites a single node, then transform f t
is the result of running f
on all nodes within t
in a bottom-up fashion.
transformM :: forall f m. (HTraversable f, Monad m) => NatM m (HFix f) (HFix f) -> NatM m (HFix f) (HFix f) Source #
Monadic version of transform
.
query :: HFoldable f => (HFix f :=> r) -> (r -> r -> r) -> HFix f :=> r Source #
query :: (forall i. Term fs i -> r) -> (r -> r -> r) -> Term fs l -> r
Example usage: let getConsts :: (IntConst :-fs) = Term fs l -> [Int]
be
a function where getConsts (iIntConst n) = [n]
, and getConsts t = []
for everything that is not an IntConst
. Then
query getConsts (++) term
returns a list of all integer constants in term
.