diff --git a/lib/ocaml/test.sh b/lib/ocaml/test.sh index 39414caf..d3a1fe03 100755 --- a/lib/ocaml/test.sh +++ b/lib/ocaml/test.sh @@ -1254,6 +1254,14 @@ cat > "$TMPFILE" << 'EPOCHS' (epoch 4991) (eval "(ocaml-run \"List.find_map (fun x -> if x > 5 then Some (x * 2) else None) [1;2;3;6;7]\")") +;; ── Polymorphic variants ────────────────────────────────────── +(epoch 5000) +(eval "(ocaml-run \"let x = `Foo in match x with `Foo -> 1 | `Bar -> 2\")") +(epoch 5001) +(eval "(ocaml-run \"let x = `Pair (5, 7) in match x with `Pair (a, b) -> a + b | _ -> 0\")") +(epoch 5002) +(eval "(ocaml-run \"List.map (fun x -> match x with `On -> 1 | `Off -> 0) [`On; `Off; `On]\")") + EPOCHS OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null) @@ -1991,6 +1999,11 @@ check 4982 "String.of_seq (rev to_seq)" '"olleh"' check 4990 "sort_uniq dedupes & sorts" '(1 2 3 4)' check 4991 "find_map first >5 doubled" '("Some" 12)' +# ── Polymorphic variants ───────────────────────────────────────── +check 5000 'match polyvar Foo / Bar' '1' +check 5001 'match polyvar Pair (a, b)' '12' +check 5002 'List.map polyvar On / Off' '(1 0 1)' + TOTAL=$((PASS + FAIL)) if [ $FAIL -eq 0 ]; then echo "ok $PASS/$TOTAL OCaml-on-SX tests passed" diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 51ed0288..d150efe9 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,13 @@ _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 4 — polymorphic variants confirmation (+3 tests, + 506 total). The tokenizer was already classifying `` `Tag `` as a + ctor identical to a nominal one, but it had never been exercised by + tests. Now verified that nullary, n-ary, and list-of-polyvariants + patterns all match: `` `Foo``, `` `Pair (5, 7)``, `[`On; `Off]`. + Effectively free since OCaml-on-SX is dynamic — there's no + structural row inference, but matching by tag works. - 2026-05-09 Phase 6 — List.sort_uniq / List.find_map (+2 tests, 503 total). sort_uniq sorts then dedups consecutive equals. find_map walks until the user fn returns `Some v` and returns it (or `None`