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

@@ -632,6 +632,7 @@
(begin
(set! env (ocaml-env-extend env mname mod-val))
(set! result (merge result (dict mname mod-val))))))))
((= tag "type-def") nil)
((= tag "open")
(let ((mod-val (ocaml-resolve-module-path (nth decl 1) env)))
(cond
@@ -803,6 +804,11 @@
(begin
(set! env (ocaml-env-extend env mname mod-val))
(set! last mod-val))))))
((= tag "type-def")
;; type t = ... — purely declarative at runtime; ctors
;; are dispatched by tag at eval/match time. Phase 5
;; HM extensions will register ctor types here.
nil)
((or (= tag "open") (= tag "include"))
;; open M / include M — bring M's bindings into scope.
(let ((mod-val (ocaml-resolve-module-path (nth decl 1) env)))