ocaml: phase 5 HM pattern-match inference (+5 tests, 344 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

ocaml-infer-pat covers :pwild, :pvar, :plit, :pcons, :plist, :ptuple,
:pas. Returns {:type T :env ENV2 :subst S} where ENV2 has the pattern's
bound names threaded through.

ocaml-infer-match unifies each clause's pattern type with the scrutinee,
runs the body in the env extended with pattern bindings, and unifies
all body types via a fresh result tv.

Examples:
  fun lst -> match lst with | [] -> 0 | h :: _ -> h : Int list -> Int
  match (1, 2) with | (a, b) -> a + b              : Int

Constructor patterns (:pcon) fall through to a fresh tv for now —
proper handling needs a ctor type registry from 'type' declarations.
This commit is contained in:
2026-05-08 13:02:15 +00:00
parent 202ea9cf5f
commit d2bf0c0d00
3 changed files with 135 additions and 0 deletions

View File

@@ -365,6 +365,14 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
_Newest first._
- 2026-05-08 Phase 5 — HM pattern-matching inference (+5 tests, 344
total). `ocaml-infer-pat` covers wild, var, lit, cons, list, tuple,
as. `ocaml-infer-match` unifies each clause's pattern type with the
scrutinee, runs the body in the env extended with pattern-bound vars,
and unifies all body types via a fresh result tv. Examples:
`fun lst -> match lst with | [] -> 0 | h :: _ -> h : Int list -> Int`.
Constructor patterns fall through to a fresh tv for now (need a ctor
type registry from `type` decls — pending).
- 2026-05-08 Phase 6 — `List.sort` + polymorphic `compare` (+7 tests,
339 total). `compare` is a host primitive that returns -1/0/1 like
Stdlib.compare, defers to host SX `<`/`>`. `List.sort` is implemented