Skip to content

Commit 17acf9b

Browse files
hyperpolymathclaude
andcommitted
compiler: port TypeChecker.res + TypeSuperposition.res -> .affine
Modules 5 + 6 (1123 + 323 lines), both verified green with affinescript check and the full harness (all six modules ok). TypeChecker.affine: the static checker. The .res's shared-mutable env (fresh-var counter + substitution map) and checkResult.errors are unified into one immutable, threaded CheckState, returned via (result, CheckState) tuples. The lexical environment is a frame-stack [[(String, Binding)]] (head = innermost); the substitution map is an Int-keyed assoc list. Unification is faithful arm-for-arm including numeric widening and the Echo/EchoR rule: same-kind structural only, Echo<_,_> deliberately NOT unifying with EchoR<_,_> (erasure is irreversible). The Echo builtins (echo / echo_to_residue / residue_strictly_loses / echo_input / echo_output) mirror the .res including the [Stab-Erase] diagnostics. Internal `ty` constructors are C-prefixed (CInt..CVar) to avoid colliding with Types' TypeExpr. TypeSuperposition.affine: the quantum-type demo (Collapsed | Superposition(...)); the deterministic collapse index is byte-faithful. Documented faithful deviations: the .res `exprLoc` helper is omitted — `infer_expr` returns the expression's own Location (a copyable summary) alongside the type, so diagnostics keep exact locations without re-traversing a consumed node; Array.zip/every/forEach over state-mutating callbacks become state-threading folds; minor local renames to avoid global-constructor collisions. No type rule, diagnostic, Echo/EchoR behaviour, or collapse arithmetic was changed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0195yA45jSSP7YDPwJSpw4bM
1 parent 0f89d0d commit 17acf9b

2 files changed

Lines changed: 1446 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)