ocaml: phase 3 polymorphic variants (+4 tests, 382 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 46s

Tokenizer recognises backtick followed by an upper ident, emitting a
ctor token identical to a nominal ctor. Parser and evaluator treat
polyvariants as ctors — same tagged-list runtime. So:

  `Red                   -> ("Red")
  `Some 42               -> ("Some" 42)
  match `Red with | `Red -> 1 | `Green -> 2 | `Blue -> 3
                          -> 1
  `Pair (1,2)            -> ("Pair" 1 2) (with tuple-arg flatten)

Proper row types in HM deferred.
This commit is contained in:
2026-05-08 14:03:09 +00:00
parent 986b15c0e5
commit 9f539ab392
3 changed files with 40 additions and 1 deletions

View File

@@ -381,6 +381,20 @@
(slice src (+ start 1) pos)
start)
(step)))
;; Polymorphic variant tag: `Tag — emits a ctor token
;; identical to a nominal ctor. Runtime is dynamic, so
;; the distinction only matters for HM (deferred).
((and (= c "`")
(< (+ pos 1) src-len)
(ocaml-upper? (ocaml-peek 1)))
(begin
(advance! 1)
(let ((ctor-start pos))
(begin
(when (and (< pos src-len) (ocaml-ident-char? (cur)))
(begin (advance! 1) (read-ident ctor-start)))
(push! "ctor" (slice src ctor-start pos) start)))
(step)))
((try-punct start) (step))
(else
(error