Commit 3ac22ca
feat(check): make Echo types operational — typing rules for echo operations (#56)
## Summary
Echo types were **inert type formers**: `bet-check`'s unifier handled
`Echo T` / `EchoR T` (distinct from `T`, structural recursion, distinct
from each other), but **no expression could introduce or eliminate
one**. The design doc listed all the operations as "deferred".
This integrates the structured-loss operations **into the type system**
as genuinely polymorphic builtins, each instantiated with a **fresh
carrier variable per use site**:
| Operation | Typing rule | Role |
|-----------|-------------|------|
| `echo` | `'a -> Echo 'a` | introduction (`echo-intro`, unary collapse
of the fibre core) |
| `echo_output` | `Echo 'a -> 'a` | **explicit** projection to the base
value (never an implicit coercion) |
| `echo_to_residue` | `Echo 'a -> EchoR 'a` | lower a full echo to its
strict, non-recoverable residue |
| `sample_echo` | `Dist 'a -> Echo 'a` | probabilistic-support bridge:
retains the residue `sample` discards |
Wired through `Expr::Var` so **lexical bindings shadow** the builtins.
Surface syntax is ordinary application (`echo(x)`), so no grammar change
was needed.
## Design fidelity
- **Types-only / ghost.** `Echo T` / `EchoR T` still erase to `T` at
runtime — no residue payload is materialised, matching
`docs/echo-types.adoc` §"Runtime representation strategy". No
runtime/effect commitment.
- **Distinctness preserved.** Enforced *through the operations* as well
as the formers — `echo_output` on a bare carrier is rejected. No
implicit `Echo T -> T`.
- **Canonical names** mirror `hyperpolymath/echo-types` (source of
truth) and `EchoTypes.jl`.
- Deliberately **not** added: `echo_input` (coincides with `echo_output`
for the unary former), `residue_strictly_loses` (a propositional
witness, not a term), `bet_echo` (needs ternary surface form).
## Verification
- **34/34** `bet-check` tests pass (27 baseline + 7 new: intro, explicit
projection, residue lowering, `sample_echo` bridge + composition,
polymorphic reuse, bare-carrier rejection, shadowing).
- `tools/proof-scan.sh` clean — no banned soundness escape hatches.
- New library code is clippy-clean.
## Formal-proof follow-up
Lean keeps `echo`/`echoR` as type *formers* only, so
Progress/Preservation remain intact. Mirroring the operation typing
rules in Lean (and re-establishing the metatheory) is registered as
obligation **TP-5** in `PROOF-NEEDS.md` / `PROOF-STATUS.md`, deferred
until the runtime residue representation is settled.
## Files
- `compiler/bet-check/src/lib.rs` — `echo_builtin_type` + `Expr::Var`
wiring + tests
- `docs/echo-types.adoc` — new "Operations (typing rules)" section;
narrowed deferral list
- `README.adoc` — Echo Types section updated
- `PROOF-NEEDS.md` / `PROOF-STATUS.md` — TP-5 registered
- `proofs/BetLang.lean` — comment-only pointer to the landed rules +
TP-5
https://claude.ai/code/session_01QGi8GND5yNWgDyfReVEPYs
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QGi8GND5yNWgDyfReVEPYs)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 01512e7 commit 3ac22ca
6 files changed
Lines changed: 425 additions & 33 deletions
File tree
- compiler/bet-check/src
- docs
- proofs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| 86 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
145 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
| |||
437 | 445 | | |
438 | 446 | | |
439 | 447 | | |
440 | | - | |
| 448 | + | |
441 | 449 | | |
442 | 450 | | |
443 | 451 | | |
| |||
0 commit comments