tree
data Tree (A : Type)A binary tree with values of A at its nodes.
Tree.size
Section titled “Tree.size”def size {A : Type} (t : Tree A) : NatThe number of nodes.
Tree.leafCount
Section titled “Tree.leafCount”def leafCount {A : Type} (t : Tree A) : NatThe number of leaves (one more than the nodes).
Tree.depth
Section titled “Tree.depth”def depth {A : Type} (t : Tree A) : NatThe number of nodes on the longest path from the root to a leaf.
Tree.map
Section titled “Tree.map”def map {A : Type} {B : Type} (f : A -> B) (t : Tree A) : Tree Bf applied to every value, the shape kept.
Tree.mirror
Section titled “Tree.mirror”def mirror {A : Type} (t : Tree A) : Tree AThe subtrees swapped at every node.
Tree.zip
Section titled “Tree.zip”def zip {A : Type} {B : Type} (a : Tree A) (b : Tree B) : Tree (A * B)The pairs of values where both trees have a node.
Tree.fold
Section titled “Tree.fold”def fold {A : Type} {B : Type} (atLeaf : B) (f : A -> B -> B -> B) (t : Tree A) : BThe values from the leaves up: atLeaf at each leaf, f x left right at each node.
Tree.inorder
Section titled “Tree.inorder”def inorder {A : Type} (t : Tree A) : List AThe values in order: the left subtree, the node, the right subtree.
Tree.preorder
Section titled “Tree.preorder”def preorder {A : Type} (t : Tree A) : List AThe values with each node before its subtrees.
Tree.postorder
Section titled “Tree.postorder”def postorder {A : Type} (t : Tree A) : List AThe values with each node after its subtrees.
Tree.all
Section titled “Tree.all”def all {A : Type} (test : A -> Bool) (t : Tree A) : BoolWhether every value passes the test.
Tree.any
Section titled “Tree.any”def any {A : Type} (test : A -> Bool) (t : Tree A) : BoolWhether some value passes the test.
Tree.root
Section titled “Tree.root”def root {A : Type} (t : Tree A) : Option AThe value at the root, if the tree is a node.
Tree.leftSubtree
Section titled “Tree.leftSubtree”def leftSubtree {A : Type} (t : Tree A) : Tree AThe left subtree of a node; a leaf’s is a leaf.
Tree.rightSubtree
Section titled “Tree.rightSubtree”def rightSubtree {A : Type} (t : Tree A) : Tree AThe right subtree of a node; a leaf’s is a leaf.
Tree.insertLeft
Section titled “Tree.insertLeft”def insertLeft {A : Type} (x : A) (t : Tree A) : Tree AA new node with x at the leftmost leaf.
Tree.insertRight
Section titled “Tree.insertRight”def insertRight {A : Type} (x : A) (t : Tree A) : Tree AA new node with x at the rightmost leaf.
Tree.mapIdentity
Section titled “Tree.mapIdentity”def mapIdentity {A : Type} (t : Tree A) : map (fun (x : A) => x) t = tMapping the identity changes nothing.
Tree.mapCompose
Section titled “Tree.mapCompose”def mapCompose {A : Type} {B : Type} {C : Type} (f : A -> B) (g : B -> C) (t : Tree A) : map g (map f t) = map (fun (x : A) => g (f x)) tMapping twice is mapping the composition.
Tree.sizeMap
Section titled “Tree.sizeMap”def sizeMap {A : Type} {B : Type} (f : A -> B) (t : Tree A) : size (map f t) = size tMapping keeps the size.
Tree.mirrorMirror
Section titled “Tree.mirrorMirror”def mirrorMirror {A : Type} (t : Tree A) : mirror (mirror t) = tMirroring twice gives the tree back.
Tree.sizeMirror
Section titled “Tree.sizeMirror”def sizeMirror {A : Type} (t : Tree A) : size (mirror t) = size tMirroring keeps the size.
Tree.depthMirror
Section titled “Tree.depthMirror”def depthMirror {A : Type} (t : Tree A) : depth (mirror t) = depth tMirroring keeps the depth.
Tree.mirrorMap
Section titled “Tree.mirrorMap”def mirrorMap {A : Type} {B : Type} (f : A -> B) (t : Tree A) : mirror (map f t) = map f (mirror t)Mirroring and mapping commute.