From 24416f8cef3be78b470f518ab31d76331e96bb61 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 9 May 2026 05:44:35 +0000 Subject: [PATCH] ocaml: phase 5.1 unique_set.ml baseline (Set.Make + IntOrd, count = 9) First baseline that exercises the functor pipeline end to end: module IntOrd = struct type t = int let compare a b = a - b end module IntSet = Set.Make (IntOrd) let unique_count xs = let s = List.fold_left (fun s x -> IntSet.add x s) IntSet.empty xs in IntSet.cardinal s Counts unique elements in [3;1;4;1;5;9;2;6;5;3;5;8;9;7;9]: {1,2,3,4,5,6,7,8,9} -> 9 The input has 15 elements with 9 unique values. The 'type t = int' declaration in IntOrd is required by real OCaml; OCaml-on-SX is dynamic and would accept it without, but we include it for source fidelity. 27 baseline programs total. --- lib/ocaml/baseline/expected.json | 1 + lib/ocaml/baseline/unique_set.ml | 14 ++++++++++++++ plans/ocaml-on-sx.md | 6 ++++++ 3 files changed, 21 insertions(+) create mode 100644 lib/ocaml/baseline/unique_set.ml diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index b2a4af71..6f5186e2 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -26,5 +26,6 @@ "roman.ml": 44, "sieve.ml": 15, "sum_squares.ml": 385, + "unique_set.ml": 9, "word_count.ml": 3 } diff --git a/lib/ocaml/baseline/unique_set.ml b/lib/ocaml/baseline/unique_set.ml new file mode 100644 index 00000000..3a3ba483 --- /dev/null +++ b/lib/ocaml/baseline/unique_set.ml @@ -0,0 +1,14 @@ +module IntOrd = struct + type t = int + let compare a b = a - b +end + +module IntSet = Set.Make (IntOrd) + +let unique_count xs = + let s = List.fold_left (fun s x -> IntSet.add x s) IntSet.empty xs in + IntSet.cardinal s + +;; + +unique_count [3; 1; 4; 1; 5; 9; 2; 6; 5; 3; 5; 8; 9; 7; 9] diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index bce487b0..0c9fe76f 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 — unique_set.ml baseline (Set.Make + IntOrd + functor app, count uniques in [3;1;4;1;5;9;2;6;5;3;5;8;9;7;9] → + 9). First baseline that exercises the functor pipeline end to + end: defines an Ord module with `type t = int` + `compare`, applies + Set.Make to it, then folds the input list adding each element to + the set and queries `IntSet.cardinal`. 27 baseline programs total. - 2026-05-09 Phase 4 — Set.Make / Map.Make functor application smoke tests (+3 tests, 572 total). Functors were already wired through ocaml-make-functor in eval.sx but had no explicit tests