ocaml: phase 5 HM tuple + list types (+7 tests, 326 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 29s

Tuple type (hm-con "*" TYPES); list type (hm-con "list" (TYPE)).
ocaml-infer-tuple threads substitution through each item left-to-right.
ocaml-infer-list unifies all items with a fresh 'a (giving 'a list for
empty []).

Pretty-printer renders 'Int * Int' for tuples and 'Int list' for lists,
matching standard OCaml notation.

Examples:
  fun x y -> (x, y) : 'a -> 'b -> 'a * 'b
  fun x -> [x; x] : 'a -> 'a list
  []                : 'a list
This commit is contained in:
2026-05-08 12:54:15 +00:00
parent a0abdcf520
commit 6d7197182e
3 changed files with 92 additions and 1 deletions

View File

@@ -798,6 +798,22 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1422)
(eval "(ocaml-run \"Result.map_error (fun e -> e + 1) (Error 5)\")")
;; ── HM extensions: tuples + lists ──────────────────────────────
(epoch 1500)
(eval "(ocaml-type-of \"(1, 2)\")")
(epoch 1501)
(eval "(ocaml-type-of \"(1, true, \\\"hi\\\")\")")
(epoch 1502)
(eval "(ocaml-type-of \"[1; 2; 3]\")")
(epoch 1503)
(eval "(ocaml-type-of \"[]\")")
(epoch 1504)
(eval "(ocaml-type-of \"fun x -> [x; x]\")")
(epoch 1505)
(eval "(ocaml-type-of \"fun x y -> (x, y)\")")
(epoch 1506)
(eval "(ocaml-type-of \"[true; false]\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1263,6 +1279,15 @@ check 1420 "Result.get_ok" '42'
check 1421 "Result.to_option Ok" '("Some" 1)'
check 1422 "Result.map_error" '("Error" 6)'
# ── HM tuples + lists ───────────────────────────────────────────
check 1500 "type tuple Int*Int" '"Int * Int"'
check 1501 "type 3-tuple" '"Int * Bool * String"'
check 1502 "type Int list" '"Int list"'
check 1503 "type [] poly" ' list'
check 1504 "type fn -> list" 'list"'
check 1505 "type fn -> tuple" ' * '
check 1506 "type Bool list" '"Bool list"'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"