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

Moduletree-diff-0.3.4Haskell2010

Data.TreeDiff.Tree

Tree diffing working on containers Tree.

  • 2 types
  • 1 value
  • Packagetree-diff-0.3.4
  • Exports3
  • LanguageHaskell2010
  • LicenceGPL-2.0-or-later
  • SourceTree.hs
valuetreeDiff :: (Show a, Eq a) => Tree a -> Tree a -> Edit (EditTree a)
#

A breadth-traversal diff.

It's different from gdiff, as it doesn't produce a flat edit script, but edit script iself is a tree. This makes visualising the diff much simpler.

Examples

Let's start from simple tree. We pretty print them as s-expressions.

Example2 expressions
let x = Node 'a' [Node 'b' [], Node 'c' [return 'd', return 'e'], Node 'f' []]ppTree PP.char x(a b (c d e) f)

If we modify an argument in a tree, we'll notice it's changed:

Example2 expressions
let y = Node 'a' [Node 'b' [], Node 'c' [return 'x', return 'e'], Node 'f' []]ppTree PP.char y(a b (c x e) f)
Example1 expression
ppEditTree PP.char (treeDiff x y)(a b (c -d +x e) f)

If we modify a constructor, the whole sub-trees is replaced, though there might be common subtrees.

Example2 expressions
let z = Node 'a' [Node 'b' [], Node 'd' [], Node 'f' []]ppTree PP.char z(a b d f)
Example1 expression
ppEditTree PP.char (treeDiff x z)(a b -(c d e) +d f)

If we add arguments, they are spotted too:

Example2 expressions
let w = Node 'a' [Node 'b' [], Node 'c' [return 'd', return 'x', return 'e'], Node 'f' []]ppTree PP.char w(a b (c d x e) f)
Example1 expression
ppEditTree PP.char (treeDiff x w)(a b (c d +x e) f)
datadata EditTree a
#

Type used in the result of treeDiff.

It's essentially a Tree, but the forest list is changed from [tree a] to [Edit (tree a)]. This highlights that treeDiff performs a list diff on each tree level.

Constructors

Instances1Show
datadata Edit a
#

List edit operations

The Swp constructor is redundant, but it let us spot a recursion point when performing tree diffs.

Constructors

  • Ins a

    insert

  • Del a

    delete

  • Cpy a

    copy unchanged

  • Swp a a

    swap, i.e. delete + insert

Instances3Eq, Show, NFData
  • Eq a => Eq (Edit a)Defined in tree-diff-0.3.4 · Data.TreeDiff.List
  • Show a => Show (Edit a)Defined in tree-diff-0.3.4 · Data.TreeDiff.List
  • NFData a => NFData (Edit a)Defined in tree-diff-0.3.4 · Data.TreeDiff.List