Data.Tree.NTree.Edit

hxt-9.3.1.16: A collection of tools for processing XML with Haskell.

License | MIT
Maintainer | Uwe Schmidt (uwe\@fh-wedel.de)
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Data.Tree.NTree.Edit

Description

Space and time efficient editing of rose trees

Synopsis

- editNTreeBottomUp :: (NTree a -> Maybe [NTree a]) -> NTree a -> [NTree a]
- mapNTree' :: (a -> Maybe a) -> NTree a -> NTree a

# Documentation

editNTreeBottomUp :: (NTree a -> Maybe [NTree a]) -> NTree a -> [NTree a] #

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

mapNTree' :: (a -> Maybe a) -> NTree a -> NTree a #

A space optimized map for NTrees

Subtrees, that are not changed are reused in the resulting tree See also: editNTreeBottomUp