ocaml: phase 5 HM ctor inference for option/result (+7 tests, 351 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s

ocaml-hm-ctor-env registers None/Some : 'a -> 'a option, Ok/Error :
'a -> ('a, 'b) result. :con NAME instantiates the scheme; :pcon NAME
ARG-PATS walks arg patterns through the constructor's arrow type,
unifying each.

Pretty-printer renders 'Int option' and '(Int, 'b) result'.

Examples now infer:
  fun x -> Some x : 'a -> 'a option
  match Some 5 with | None -> 0 | Some n -> n : Int
  fun o -> match o with | None -> 0 | Some n -> n : Int option -> Int
  Ok 1 : (Int, 'b) result
  Error "oops" : ('a, String) result

User type-defs would extend the registry — pending.
This commit is contained in:
2026-05-08 13:05:22 +00:00
parent d2bf0c0d00
commit 81247eb6ea
3 changed files with 109 additions and 2 deletions

View File

@@ -856,6 +856,22 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1804)
(eval "(ocaml-type-of \"fun lst -> match lst with | [] -> 0 | h :: _ -> h\")")
;; ── HM constructor inference (option/result) ───────────────────
(epoch 1900)
(eval "(ocaml-type-of \"Some 5\")")
(epoch 1901)
(eval "(ocaml-type-of \"None\")")
(epoch 1902)
(eval "(ocaml-type-of \"Ok 1\")")
(epoch 1903)
(eval "(ocaml-type-of \"Error \\\"oops\\\"\")")
(epoch 1904)
(eval "(ocaml-type-of \"fun x -> Some x\")")
(epoch 1905)
(eval "(ocaml-type-of \"match Some 5 with | None -> 0 | Some n -> n\")")
(epoch 1906)
(eval "(ocaml-type-of \"fun o -> match o with | None -> 0 | Some n -> n\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1354,6 +1370,15 @@ check 1802 "match tuple" '"Int"'
check 1803 "fn match int -> int" '"Int -> Int"'
check 1804 "fn list -> elem" '"Int list -> Int"'
# ── HM ctor inference ──────────────────────────────────────────
check 1900 "Some 5 : Int option" '"Int option"'
check 1901 "None : 'a option" ' option'
check 1902 "Ok 1 : (Int, 'b) result" '"(Int'
check 1903 "Error 'oops'" 'String) result'
check 1904 "fun x -> Some x" ' option'
check 1905 "match Some/None -> Int" '"Int"'
check 1906 "Int option -> Int" '"Int option -> Int"'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"