You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(types): accommodate Echo types (structured loss) in the type checker
Add the `Echo T` / `EchoR T` type formers from hyperpolymath/echo-types
across betlang's type-system surfaces. `Echo T` is a distinct,
proof-relevant structured-loss residue over `T`; `EchoR T` is its strict,
non-recoverable weakening (reserved — operations deferred).
Design (per maintainer direction):
- Distinct from the carrier: unify(Echo T, T) and unify(Echo T, EchoR T)
both fail; no implicit forgetting Echo T -> T.
- Domain-agnostic in core; the canonical betlang introduction site is
probabilistic-support retention (a future `sample_echo : Dist T -> Echo T`
keeps the draw/branch residue that `sample` marginalises away).
- Ghost/proof-relevant residue: erases to T's representation at runtime;
no runtime payload yet.
Surfaces:
- compiler/bet-core/src/types.rs: Type::Echo / Type::EchoR variants.
- compiler/bet-check/src/lib.rs: lower `Echo T`/`EchoR T` (type
applications) in ast_type_to_core; structural resolve/unify; distinctness
via the mismatch fallthrough. Adds 5 unit tests (lowering, distinctness,
structural unification, Echo != EchoR, inference recursion) and fixes the
test module's missing `Symbol` import (tests never compiled under
`cargo check`). `cargo test -p bet-check`: 27 passed.
- proofs/BetLang.lean: Ty.echo / Ty.echoR formers (no Expr/HasType use, so
Progress/Preservation are unaffected).
- spec/SPEC.core.scm + spec/grammar.ebnf: echo-types semantics entry and
grammar note.
- docs/echo-types.adoc: design + deferred-work writeup.
https://claude.ai/code/session_01NGKc4681nuptfQADqreAfc
. "Echo T is a distinct proof-relevant structured-loss type whose first canonical betlang introduction form is probabilistic support retention: sampling or betting may erase branch/draw information into T, while the echo form retains that residue statically.")
141
+
142
+
(formers
143
+
. ((Echo . ((arity . 1)
144
+
(meaning . "Echo T : a T-value carrying a proof-relevant residue of retained loss; potentially recoverability-bearing")
145
+
(surface-syntax . "Echo T (parsed as a type application, like `Dist T`)")))
146
+
(EchoR . ((arity . 1)
147
+
(meaning . "EchoR T : the strict, non-recoverable residue/retraction of Echo T; no recovery operation is promised")
. ((distinctness . "Echo T is NOT T: unify(Echo T, T) fails and unify(Echo T, EchoR T) fails. No implicit forgetting Echo T -> T.")
152
+
(structural . "Echo T ~ Echo T' iff T ~ T'; likewise EchoR T ~ EchoR T'.")
153
+
(domain-agnostic . "Echo is the general structured-loss former in core; the probabilistic-support bridge is its canonical betlang integration, not its definition.")))
154
+
155
+
(canonical-bridge
156
+
. ((sample . "sample : Dist T -> T (marginalises away which draw/branch produced the value)")
157
+
(echo-companion . "sample_echo / bet_echo : Dist T -> Echo T (retains that residue) -- DEFERRED")))
158
+
159
+
(runtime . "Residue is ghost / proof-relevant: Echo T and EchoR T erase to T's representation in codegen for now (no runtime payload until operations demand it).")
160
+
161
+
(mechanisation . "Type formers Ty.echo / Ty.echoR in proofs/BetLang.lean; Type::Echo / Type::EchoR in compiler/bet-core/src/types.rs; lowered + unified (distinctly) in compiler/bet-check.")))
0 commit comments