diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 4d72e60d..208228be 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -61,6 +61,7 @@ "subset_sum.ml": 8, "tic_tac_toe.ml": 1, "word_freq.ml": 8, + "zigzag.ml": 55, "zip_unzip.ml": 1000, "sieve.ml": 15, "sum_squares.ml": 385, diff --git a/lib/ocaml/baseline/zigzag.ml b/lib/ocaml/baseline/zigzag.ml new file mode 100644 index 00000000..710644f0 --- /dev/null +++ b/lib/ocaml/baseline/zigzag.ml @@ -0,0 +1,8 @@ +let rec zigzag xs ys = + match xs with + | [] -> ys + | x :: xs' -> x :: zigzag ys xs' + +;; + +List.fold_left (+) 0 (zigzag [1;3;5;7;9] [2;4;6;8;10]) diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 153ed59f..09bcf0a2 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,12 @@ _Newest first._ binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree * 'a tree`) with insert + in-order traversal. Tests parametric ADT, recursive match, List.append, List.fold_left. +- 2026-05-09 Phase 5.1 — zigzag.ml baseline (interleave two lists, + sum 1..10 = 55). One-liner that swaps the lists on every recursive + call: `match xs with [] -> ys | x :: xs' -> x :: zigzag ys xs'`. + zigzag [1;3;5;7;9] [2;4;6;8;10] = [1;2;3;4;5;6;7;8;9;10] sum 55. + Tests recursive list cons + arg-swap idiom. 68 baseline programs + total. - 2026-05-09 Phase 5.1 — prefix_sum.ml baseline (precomputed prefix sums for O(1) range queries, sum of three queries = 66). prefix_sums xs returns an Array of len n+1 such that