Tree package:hxt
The interface for navigatable tree arrows
all functions have default implementations
Change the current subtree of a navigatable tree.
The arrow for computing the changes should be deterministic. If it
fails nothing is changed.
Substitute the current subtree of a navigatable tree by a given tree
List arrows for tree processing.
Trees that implement the
Data.Tree.Class interface, can be
processed with these arrows.
The interface for tree arrows
all functions have default implementations
an arrow for inserting a whole subtree with some holes in it (a
template) into a document. The holes can be filled with contents from
the input.
Example
insertTreeTemplateTest :: ArrowXml a => a b XmlTree
insertTreeTemplateTest
= doc
>>>
insertTreeTemplate template pattern
where
doc -- the input data
= constA "<x><y>The Title</y><z>The content</z></x>"
>>> xread
template -- the output template with 2 holes: xxx and yyy
= constA "<html><head><title>xxx</title></head><body><h1>yyy</h1></body></html>"
>>> xread
pattern
= [ hasText (== "xxx") -- fill the xxx hole with the input contents from element "x/y"
:-> ( getChildren >>> hasName "y" >>> deep isText )
, hasText (== "yyy") -- fill the yyy hole with the input contents from element "x/z"
:-> ( getChildren >>> hasName "z" >>> getChildren )
]
computes the XML tree for the following document
"<html><head><title>The Title</title></head><body><h1>The content</h1></body></html>"
arrows for efficient editing of rose trees
Edit parts of a rose tree
The subtrees to be modified are selected by the first part of the
IfThen pairs The modification by the second part
number of nodes in a tree
convert a tree into a pseudo graphical string representation
format tree for readable trace output
a graphical representation of the tree in text format
tree construction: a new tree is constructed by a node attribute and a
list of children
editNTreeBottomUp is a space optimized tree edit function
The nodes in a tree are visited bottom up. An edit function is applied
to all nodes. A Nothing result of the editing function indicates no
changes. This is used to share the input tree within the resulting
tree.
The following law holds:
editNTreeBottomUp (const Nothing) t == [t]
In this case the resulting tree does not only represent the same value
but it is the same machine value (relative to some evaluations of
closures during the tree walk
With a simple fold like editing function the whole tree would be
reconstructed in memory
A space optimized map for NTrees
Subtrees, that are not changed are reused in the resulting tree See
also: editNTreeBottomUp
n-ary ordered tree (rose trees)
a tree consists of a node and a possible empty list of children. If
the list of children is empty, the node is a leaf, else it's an inner
node.
NTree implements Eq, Ord, Show and Read
shortcut for a sequence of n-ary trees