English
There exists a canonical pretty-printer for Ordnode trees that outputs a structured representation showing the left subtree, the node value, and the right subtree; the empty tree is printed as ∅.
Русский
Существует каноничный форматированный вывод для деревьев Ordnode, который отображает левое поддерево, значение узла и правое поддерево; пустое дерево выводится как ∅.
LaTeX
$$$$ \text{repr}: \ Ordnode\; \alpha \to \mathbb{N} \to \mathrm{Std.Format}, \quad \text{repr}(\text{nil}, n) = ∅, \\ \text{repr}(\text{node}\; sz\; l\; x\; r, n) = \mathrm{Std.Format.paren}(\mathrm{Std.Format.joinSep}([\text{repr}(l,n), \mathrm{Repr.reprPrec}(x,n), \text{repr}(r,n)], \text{" "})) $$$$
Lean4
/-- Basic pretty printing for `Ordnode α` that shows the structure of the tree.
repr {3, 1, 2, 4} = ((∅ 1 ∅) 2 ((∅ 3 ∅) 4 ∅)) -/
def repr {α} [Repr α] (o : Ordnode α) (n : ℕ) : Std.Format :=
match o with
| nil => (Std.Format.text "∅")
| node _ l x r =>
let fmt := Std.Format.joinSep [repr l n, Repr.reprPrec x n, repr r n] " "
Std.Format.paren fmt