Commit Graph

1 Commits

Author SHA1 Message Date
027678f31e ocaml: phase 5.1 flatten_tree.ml baseline (parametric ADT flatten, sum 1..7 = 28)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Defines a parametric tree:

  type 'a tree = Leaf of 'a | Node of 'a tree list

  let rec flatten t =
    match t with
    | Leaf x -> [x]
    | Node ts -> List.concat (List.map flatten ts)

Test tree has 3 levels of nesting:

  Node [Leaf 1; Node [Leaf 2; Leaf 3];
        Node [Node [Leaf 4]; Leaf 5; Leaf 6];
        Leaf 7]

flattens to [1;2;3;4;5;6;7] -> sum = 28.

Tests parametric ADT, mutual recursion via map+self, List.concat.

55 baseline programs total.
2026-05-09 11:52:19 +00:00