HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehxt-9.3.1.22Haskell2010

Data.Tree.NTree.Edit

Space and time efficient editing of rose trees

  • 2 values
  • Packagehxt-9.3.1.22
  • Exports2
  • LanguageHaskell2010
  • LicenceMIT
  • SourceEdit.hs
valueeditNTreeBottomUp :: (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

valuemapNTree' :: (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