Substitution of subtrees of a rose tree #
RoseTree.modifyIf p f applies f to every outermost subtree satisfying p, and
RoseTree.replaceIf p r replaces each by r. The subtrees modified are RoseTree.outerMatches p,
those satisfying p among the subtrees reached without passing through one
(RoseTree.subtreesUntil p); the first match in preorder is among them, and replacing them trades
their leaves for copies of the replacement's.
Main definitions #
Main results #
RoseTree.mem_outerMatches_of_find?: the first match in preorder is an outermost one.RoseTree.leaves_replaceIf: substitution trades the leaves of the replaced subtrees for those of the replacement.RoseTree.filterMap_leaves_replaceIf_add: replacing the copies of a subtree whose leaves occur once trades the leaves of one copy.
Apply f to every outermost subtree satisfying p, testing each subtree before its
children.
Equations
- RoseTree.modifyIf p f (RoseTree.node a cs) = if p (RoseTree.node a cs) then f (RoseTree.node a cs) else RoseTree.node a (RoseTree.modifyIfList p f cs)
Instances For
modifyIf in each tree of a list.
Equations
- RoseTree.modifyIfList p f [] = []
- RoseTree.modifyIfList p f (c :: cs) = RoseTree.modifyIf p f c :: RoseTree.modifyIfList p f cs
Instances For
Replace every outermost subtree satisfying p by r.
Equations
- RoseTree.replaceIf p r = RoseTree.modifyIf p fun (x : RoseTree α) => r
Instances For
The subtrees reached in preorder without passing through a subtree satisfying p, those
satisfying it included.
Equations
- RoseTree.subtreesUntil p (RoseTree.node a cs) = RoseTree.node a cs :: if p (RoseTree.node a cs) then [] else RoseTree.subtreesUntilList p cs
Instances For
subtreesUntil of the trees of a list.
Equations
- RoseTree.subtreesUntilList p [] = []
- RoseTree.subtreesUntilList p (c :: cs) = RoseTree.subtreesUntil p c ++ RoseTree.subtreesUntilList p cs
Instances For
The outermost subtrees satisfying p, in preorder: those modifyIf p modifies.
Equations
- RoseTree.outerMatches p t = List.filter (fun (x : RoseTree α) => decide (p x)) (RoseTree.subtreesUntil p t)
Instances For
The first subtree in preorder satisfying p is an outermost one.
Substitution trades the leaves of the replaced subtrees for copies of the replacement's.
When the outermost matches all have the same leaves under g, the replacement has none, and
no g-value occurs twice among the leaves of t, replacing trades the leaves of one match.