Binary tree #
Provides binary tree storage for values of any type, with O(lg n) retrieval.
See also Lean.Data.RBTree
for red-black trees - this version allows more operations
to be defined and is better suited for in-kernel computation.
We also specialize for Tree Unit
, which is a binary tree without any
additional data. We provide the notation a △ b
for making a Tree Unit
with children
a
and b
.
References #
https://leanprover-community.github.io/archive/stream/113488-general/topic/tactic.20question.html
Equations
Equations
- instReprTree = { reprPrec := reprTree✝ }
Equations
- Tree.instInhabited = { default := Tree.nil }
def
Tree.traverse
{m : Type u_1 → Type u_2}
[Applicative m]
{α : Type u_3}
{β : Type u_1}
(f : α → m β)
:
Do an action for every node of the tree.
Actions are taken in node -> left subtree -> right subtree recursive order.
This function is the traverse
function for the Traversable Tree
instance.
Equations
- Tree.traverse f Tree.nil = pure Tree.nil
- Tree.traverse f (Tree.node a a_1 a_2) = Tree.node <$> f a <*> Tree.traverse f a_1 <*> Tree.traverse f a_2
Instances For
theorem
Tree.traverse_pure
{α : Type u}
(t : Tree α)
{m : Type u → Type u_1}
[Applicative m]
[LawfulApplicative m]
:
A node with Unit
data
Equations
- Tree.«term_△_» = Lean.ParserDescr.trailingNode `Tree.«term_△_» 65 66 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " △ ") (Lean.ParserDescr.cat `term 65))