Annotations-0.2: Constructing, analyzing and destructing annotated trees

Safe HaskellSafe-Infered




type AnnFix x s = HFix (K x :*: PF s)Source

A fully annotated tree.

type AnnFix1 x s = PF s (AnnFix x s)Source

A functor with fully annotated children.

mkAnnFix :: x -> AnnFix1 x s ix -> AnnFix x s ixSource

Supply a tree with an annotation at the top level.

type AnyAnnFix x s = AnyF s (AnnFix x s)Source

A fixpoint of a data family s annotated with an x at every recursive position, with existentially quantified top-level index.

unannotate :: HFunctor s (PF s) => s ix -> AnnFix x s ix -> HFix (PF s) ixSource

Removes all annotations from a recursively annotated fixpoint.

children :: HFunctor s f => s ix -> f r ix -> [AnyF s r]Source

Collects the direct children of a functor in a list.

flatten :: forall s x ix. (HFunctor s (PF s), Fam s) => s ix -> AnnFix x s ix -> [(x, Any s)]Source

Flatten an annotated tree to a list of subtrees coupled with their annotations.

filterAnnFix :: (Fam s, HFunctor s (PF s)) => s ix -> (x -> Bool) -> AnnFix x s ix -> [(x, Any s)]Source

Yield all subtrees whose annotation matches the predicate.

debugFlatten :: (HFunctor s (PF s), ShowFam s, Show x, Fam s) => s ix -> AnnFix x s ix -> IO ()Source

Flatten an annotated tree and print all subtrees to stdout.

allAnnotations :: HFunctor phi (PF phi) => phi ix -> AnnFix x phi ix -> [x]Source

Recursively yield all annotations in the tree in preorder.

type AnnZipper phi x = FixZipper phi (K x :*: PF phi)Source

focusAnn :: Loc phi f (HFix (K x :*: g)) ix -> xSource

Extract the annotation of the current focus.

explore :: Zipper phi (PF phi) => phi ix -> (x -> ExploreHints) -> AnnFix x phi ix -> [AnnZipper phi x ix]Source

Explore an annotated tree. Starting with the root of the tree, at each position the annotation at that position is matched against the ExploreHints predicates and all the selections where matchHere was positive are collected. The exploreRight and exploreDown allow pruning of the tree, preventing entire parts from being visited.

findLeftmostDeepest :: Zipper phi (PF phi) => phi ix -> (x -> Bool) -> AnnFix x phi ix -> Maybe (AnnZipper phi x ix)Source

Find the deepest node in an annotated tree that matches the predicate. Starting with the root, the predicate tells whether a node's annotation matches. If so, the search continues at the node's children and the node's siblings to the right are excluded from further exploration. If no child matches, the node itself is returned.