ocaml: phase 4 polymorphic variants confirmation (+3 tests, 506 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Tokenizer already classified backtick-uppercase as a ctor identical
to a nominal one, but it had never been exercised by the suite. This
commit adds three smoke tests confirming that nullary, n-ary, and
list-of-polyvariant patterns all match:
let x = polyvar(Foo) in match x with polyvar(Foo) -> 1 | polyvar(Bar) -> 2
let x = polyvar(Pair) (5, 7) in
match x with polyvar(Pair) (a, b) -> a + b | _ -> 0
List.map (fun x -> match x with polyvar(On) -> 1 | polyvar(Off) -> 0)
[polyvar(On); polyvar(Off); polyvar(On)]
(In the actual SX, polyvar(X) is the literal backtick-X — backticks
in this commit message are escaped to avoid shell interpretation.)
Since OCaml-on-SX is dynamic, there's no structural row inference,
but matching by tag works.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user