ocaml: phase 3 type declarations (+5 tests, 300 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s

Parser: type [PARAMS] NAME = | Ctor [of T1 [* T2]*] | ...
- PARAMS: optional 'a or ('a, 'b) tyvar list
- AST: (:type-def NAME PARAMS CTORS) with each CTOR (NAME ARG-SOURCES)
- Argument types captured as raw source strings (treated opaquely at
  runtime since ctor dispatch is dynamic)

Runtime is a no-op — constructors and pattern matching already work
dynamically. Phase 5 will use these decls to register ctor types for
HM checking.
This commit is contained in:
2026-05-08 12:32:39 +00:00
parent 851e0585cf
commit d8f6250962
4 changed files with 110 additions and 3 deletions

View File

@@ -167,9 +167,10 @@ SX CEK evaluator (both JS and OCaml hosts)
### Phase 3 — ADTs + pattern matching
- [ ] `type` declarations: `type t = A | B of t1 * t2 | C of { x: int }`.
_(Parser + evaluator currently inferred-arity at runtime; type decls
pending.)_
- [x] `type` declarations: `type [params] t = | A | B of t1 [* t2] | `.
Parser emits `(:type-def NAME PARAMS CTORS)`. Runtime treats decls
as no-ops since constructors are dispatched dynamically by tag.
Phase 5 will register ctor types here for HM checking.
- [x] Constructors as tagged lists: `A` → `("A")`, `B(1, "x")` → `("B" 1 "x")`.
- [~] `match`/`with`: constructor, literal, variable, wildcard, tuple, list
cons/nil, nested patterns. _(Pending: `as` binding, or-patterns,
@@ -357,6 +358,13 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
_Newest first._
- 2026-05-08 Phase 3 — `type` declarations (+5 tests, 300 total). Parser
handles `type [PARAMS] NAME = | Ctor [of T1 [* T2]*] | ...`, with
optional `'a` or `('a, 'b)` type parameters. Argument types are
captured as raw source strings (treated opaquely at runtime). Runtime
is a no-op since ctor application + match already work dynamically.
300th test! Constructors `Red`/`Green`/`Blue` and `Circle of int` /
`Square of int` round-trip through parse + eval cleanly.
- 2026-05-08 Phase 3 — `as` aliases + `when` guards in match (+6 tests,
295 total). Parser: pattern parser wraps with `as ident` → `(:pas
PAT NAME)`. Match's `one` consumes optional `when GUARD-EXPR` → emits