ocaml: phase 3 polymorphic variants (+4 tests, 382 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 46s

Tokenizer recognises backtick followed by an upper ident, emitting a
ctor token identical to a nominal ctor. Parser and evaluator treat
polyvariants as ctors — same tagged-list runtime. So:

  `Red                   -> ("Red")
  `Some 42               -> ("Some" 42)
  match `Red with | `Red -> 1 | `Green -> 2 | `Blue -> 3
                          -> 1
  `Pair (1,2)            -> ("Pair" 1 2) (with tuple-arg flatten)

Proper row types in HM deferred.
This commit is contained in:
2026-05-08 14:03:09 +00:00
parent 986b15c0e5
commit 9f539ab392
3 changed files with 40 additions and 1 deletions

View File

@@ -936,6 +936,16 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 2405)
(eval "(ocaml-run \"Float.ceil 3.2\")")
;; ── Polymorphic variants ──────────────────────────────────────
(epoch 2500)
(eval "(ocaml-run \"\`Red\")")
(epoch 2501)
(eval "(ocaml-run \"\`Some 42\")")
(epoch 2502)
(eval "(ocaml-run \"match \`Red with | \`Red -> 1 | \`Green -> 2 | \`Blue -> 3\")")
(epoch 2503)
(eval "(ocaml-run \"match \`Pair (1, 2) with | \`Pair (a, b) -> a + b\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1480,6 +1490,12 @@ check 2403 "Float.pow 2 10" '1024'
check 2404 "Float.floor 3.7" '3'
check 2405 "Float.ceil 3.2" '4'
# ── Polymorphic variants ───────────────────────────────────────
check 2500 "polyvar Red" '("Red")'
check 2501 "polyvar Some 42" '("Some" 42)'
check 2502 "polyvar match" '1'
check 2503 "polyvar Pair (a,b)" '3'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"