// Benchmark: Pattern matching (measures ADT performance)
// Tests: Constructor creation, pattern matching, recursion

type Tree =
    | Leaf(Int)
    | Node(Tree, Tree)

fn sumTree(tree: Tree): Int =
    match tree {
        Leaf(n) => n,
        Node(left, right) => sumTree(left) + sumTree(right)
    }

fn buildTree(depth: Int, value: Int): Tree =
    if depth <= 0 then Leaf(value)
    else Node(buildTree(depth - 1, value), buildTree(depth - 1, value + 1))

// Build a tree of depth 15 (32767 nodes) and sum it
let tree = buildTree(15, 1)
let sumResult = sumTree(tree)
