Skip to content

Instantly share code, notes, and snippets.

@lamg
lamg / print_tree.fsx
Last active May 1, 2025 11:20
Print a tree
// the trick:
// each node must be connected directly to its direct children (with visible characters)
// and indirectly (through indentation) to its children's descendants
type Tree<'a> =
| Leaf of 'a
| Branch of 'a * list<Tree<'a>>
let printTree (t: Tree<'a>) =
let connectIndent (isLast: bool) (child: string, grandChild: string list) =