Skip to content

feat(echo): echo types through the OCaml pipeline (typecheck + eval + parser) + TangleIR contract#45

Merged
hyperpolymath merged 3 commits into
mainfrom
claude/hopeful-fermi-iXnba
Jun 14, 2026
Merged

feat(echo): echo types through the OCaml pipeline (typecheck + eval + parser) + TangleIR contract#45
hyperpolymath merged 3 commits into
mainfrom
claude/hopeful-fermi-iXnba

Conversation

@hyperpolymath

@hyperpolymath hyperpolymath commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Brings echo types (and the product type) from the Lean spec (proofs/Tangle.lean, merged) into the OCaml implementation pipeline, plus the cross-repo IR contract.

2f57d64 — typechecker (typecheck.ml)

ty gains TProd/TEcho; pp_ty made rec; infer_expr gains the eight rules [T-Echo-Close]/[T-Lower]/[T-Residue]/[T-Pair]/[T-Fst]/[T-Snd]/[T-Echo-Add]/[T-Echo-Eq], mirroring HasType. AST (ast.ml) gains the eight expr forms; pretty.ml prints them.

9e1ff79 — runtime eval + surface parser

  • eval.ml: value gains VEcho/VPair; eval_expr evaluates all eight forms (mirroring the Lean small-step reducts — echoClose b ↦ VEcho(b, identity), lower/residue project, echoAdd/echoEq reuse the existing Add/Eq logic and wrap the operand pair as residue). Exhaustiveness audited across every value match.
  • lexer.mll + parser.mly + token.ml: dedicated tokens + productions (mirroring close/cap), so the surface syntax round-trips with pretty.ml (echoClose(e), pair(a, b), …).

e021007 — TangleIR threading contract (docs/spec/ECHO-TANGLEIR-THREADING.md)

TangleIR lives in KRLAdapter.jl (Julia, out of scope), so this is the contract from the semantics owner: echoClose's residue is the pre-closure braid, which is exactly what QuandleDB's quandle_presentation derives the quandle from. Specifies the IR node shape (EchoClosed(residue, result)), the consumer rule, and the conservativity invariant — for the quandle session to implement.

⚠️ Verification — please dune build compiler/

No OCaml/menhir toolchain or OCaml CI in the build environment, so none of this was compiled. It's a careful by-hand integration with a documented self-review (eval exhaustiveness audited; parser productions isomorphic to the conflict-free close/cap rules; pp_ty/pp_value made rec). The real gate is your local dune build — watch for menhir conflict warnings. One deliberate breaking change: pair/fst/snd/lower/residue/echoClose/echoAdd/echoEq are now reserved words (corpus grep found no real collisions).

🤖 Generated with Claude Code

claude added 3 commits June 14, 2026 03:24
Mirrors the Lean spec (proofs/Tangle.lean) into the OCaml checker so echo
types are a feature of the actual typechecker, not only the metatheory.

- typecheck.ml: `ty` gains `TProd of ty*ty` and `TEcho of ty*ty`; `pp_ty` is
  now `let rec` and prints them; `infer_expr` gains the eight typing rules
  [T-Echo-Close]/[T-Lower]/[T-Residue]/[T-Pair]/[T-Fst]/[T-Snd]/[T-Echo-Add]/
  [T-Echo-Eq], matching the HasType rules.
- ast.ml: `expr` gains EchoClose/Lower/Residue/Pair/Fst/Snd/EchoAdd/EchoEq.
- pretty.ml: pp_expr prints the new forms (kept exhaustive).
- eval.ml: eval_expr gets an explicit "not yet implemented" arm for the echo
  forms (runtime evaluation is a scoped follow-on; the typechecker is the
  deliverable). Stays exhaustive.

Scope: the typechecker. Surface parser syntax + runtime eval are follow-ons.

NOTE: no OCaml toolchain or OCaml CI exists in this environment, so this was
NOT compiled here — it is a careful by-hand integration (exhaustiveness audited
via the Ast-only `Twist` probe: pretty/eval/typecheck are the only exhaustive
Ast.expr matchers; compositional's of_ast_expr has a catch-all; repl matches no
expr). Verify with `dune build` in compiler/.

https://claude.ai/code/session_01PgHpCFzwYB7Qy9L6kmR8CE
Specifies how echoClose's residue (the pre-closure braid) threads through
TangleIR to QuandleDB's quandle_presentation. TangleIR itself lives in
KRLAdapter.jl (Julia, out of scope), so this is the coordination contract from
the semantics owner (tangle), not an IR code change.

https://claude.ai/code/session_01PgHpCFzwYB7Qy9L6kmR8CE
Implements the two follow-ons to the echo typechecker integration:

PART 1 — eval.ml runtime evaluation
- Add value forms VEcho (residue, result) and VPair (a, b), mirroring
  echoVal / pair in proofs/Tangle.lean.
- Replace the not-yet-implemented stub arm with real eval_expr arms for
  EchoClose / Lower / Residue / Pair / Fst / Snd / EchoAdd / EchoEq,
  following the Lean small-step Step rules (echoCloseWord, lowerVal,
  residueVal, fstPair, sndPair, echoAddNums, echoEqNums). echoAdd/echoEq
  reuse eval_binop Add / Eq for the result component.
- Extend pp_value (now recursive) with echo(...) / (...) rendering.

PART 2 — lexer.mll + parser.mly surface syntax
- Add dedicated keyword tokens ECHOCLOSE/LOWER/RESIDUE/PAIR/FST/SND/
  ECHOADD/ECHOEQ (lexer keyword table + parser %token + token.ml mirror),
  following the existing close/mirror/cap/cup mechanism.
- Add unary_expr productions in the same precedence group as close/cap,
  so pretty.ml output round-trips: echoClose(E), lower(E), residue(E),
  pair(E,E), fst(E), snd(E), echoAdd(E,E), echoEq(E,E).

https://claude.ai/code/session_01PgHpCFzwYB7Qy9L6kmR8CE
@hyperpolymath hyperpolymath changed the title feat(echo): integrate echo + product types into the OCaml typechecker feat(echo): echo types through the OCaml pipeline (typecheck + eval + parser) + TangleIR contract Jun 14, 2026
@hyperpolymath hyperpolymath marked this pull request as ready for review June 14, 2026 03:48
@hyperpolymath hyperpolymath merged commit f3ac1da into main Jun 14, 2026
11 of 12 checks passed
@hyperpolymath hyperpolymath deleted the claude/hopeful-fermi-iXnba branch June 14, 2026 03:48
hyperpolymath added a commit that referenced this pull request Jun 14, 2026
…(PRs #45–46)

- CHANGELOG.md: add echo OCaml pipeline block; fixed exhaustiveness bullets
- PROOF-NEEDS.md: TG-4 → LANDED; update rule counts (16→26 HasType, 31→57 Step); TG-10 coverage expanded to include echoAdd/echoEq/product
- PROOF-NARRATIVE.md: update HasType/Step rule lists; add §2.6 OCaml completeness table; add product/echoAdd/echoEq rows to §2.5 table; TG-4 → LANDED
- FEATURE-COVERAGE.md: add 9 echo/product rows; update coverage summary (27→36); date bump
- FORMAL-SEMANTICS.md: extend §1.2 BNF; add §1.5 extended types; add §3.16 echo/product typing rules; add §4.10 echo/product eval rules; renumber downstream sections
- STATE.a2ml: update session/last-updated/milestones/blockers/next-actions/maintenance-status
- tangle.directives.a2ml: date bump to 2026-06-14
- docs/echo-types-ocaml-pipeline.md: new developer wiki page for echo/product integration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants