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

@@ -228,7 +228,8 @@ SX CEK evaluator (both JS and OCaml hosts)
- [x] Type variables: `'a`, `'b`; unification with occur-check (kit).
- [x] Let-polymorphism: generalise at let-bindings (kit `hm-generalize`).
- [ ] ADT types: `type 'a option = None | Some of 'a`.
- [~] Function types `T1 -> T2` work; tuples/records pending.
- [~] Function types `T1 -> T2` work; tuples (`'a * 'b`) and lists
(`'a list`) supported. Records pending.
- [ ] Type signatures: `val f : int -> int` — verify against inferred type.
- [ ] Module type checking: seal against `sig` (Phase 4 stubs become real checks).
- [ ] Error reporting: position-tagged errors with expected vs actual types.
@@ -361,6 +362,13 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
_Newest first._
- 2026-05-08 Phase 5 — HM extensions for tuples and lists (+7 tests,
326 total). Tuple type `(hm-con "*" TYPES)`, list type `(hm-con
"list" (TYPE))`. `ocaml-infer-tuple` threads substitution through
each item; `ocaml-infer-list` unifies all elements with a fresh
`'a` (giving `'a list` for `[]`). Pretty-printer renders `Int * Int`
and `Int list` like real OCaml. `fun x y -> (x, y) : 'a -> 'b -> 'a
* 'b`. `fun x -> [x; x] : 'a -> 'a list`.
- 2026-05-08 Phase 6 — expanded stdlib slice (+15 tests, 319 total).
List: concat/flatten, init, find/find_opt, partition, mapi/iteri,
assoc/assoc_opt. Option: iter, fold, to_list. Result: get_ok,