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
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:
@@ -227,7 +227,10 @@ SX CEK evaluator (both JS and OCaml hosts)
|
||||
pattern matching, let-rec, modules.)_
|
||||
- [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`.
|
||||
- [~] ADT types: `option`/`result` ctors hardcoded in
|
||||
`ocaml-hm-ctor-env`; `:con NAME` and `:pcon NAME …` look up the
|
||||
scheme and instantiate. User type-defs would extend the registry.
|
||||
Format: `Int option`, `(Int, 'b) result`.
|
||||
- [~] 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.
|
||||
@@ -365,6 +368,14 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-08 Phase 5 — HM constructor inference for option/result (+7
|
||||
tests, 351 total). `ocaml-hm-ctor-env` registers None/Some (`'a opt`),
|
||||
Ok/Error (`('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:
|
||||
`fun x -> Some x : 'a -> 'a option`
|
||||
`fun o -> match o with | None -> 0 | Some n -> n : Int option -> Int`
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user