Monorepo: golang-lean (TGC) + octive-lean (TOC) + tsm-lean (TSM) + common-lean (cross-language apex).
Side-by-side comparisons of Go syntax with two Lean encodings:
* Surface AST (GolangLean.Expr) — mirrors go/ast.Node from upstream.
* Tiny Go Core (GolangLean.Core.Term) — kernel calculus with proven
operational + type semantics.
Twelve sections covering: literals, arithmetic, comparison, conditional,
variables/let-binding, functions/application, references/deref/assign,
sequencing. Each example includes a `#eval` running the term through
the proven Core.eval; output matches what's expected at run time.
Demonstrated programs:
- `(5 + 3) * 2` → 16
- `let x = 3 in let y = 7 in x < y` → true
- `(λ x. x*2) 21` → 42
- `let double = λ x. x*2 in double (double 5)` → 20
- `let p = &42 in *p = 100; *p` → 100 (heap: [vInt 100])
- higher-order: `(λ f. λ x. f (f x)) double 3` → 12
Each #eval is a runtime witness for a Core.BigStep derivation. Apply
Core.eval_sound to get a proof of the BigStep relation, and
Core.preservation to get the value's type.
Supporting changes:
- Added Repr instances for Core.Value and Core.EnvList (manual,
handling the mutual inductive — derive doesn't compose across the
mutual block).
- Added RosettaStone as a lean_lib in lakefile.toml.
|
||
|---|---|---|
| corpus | ||
| GolangLean | ||
| .gitignore | ||
| CorpusCheck.lean | ||
| GolangLean.lean | ||
| justfile | ||
| lake-manifest.json | ||
| lakefile.toml | ||
| lean-toolchain | ||
| Main.lean | ||
| README.md | ||
| RosettaStone.lean | ||
golang-lean
A Lean 4 reimplementation of the Go programming language — using the upstream reference compiler/parser as the source of truth, the way octive-lean uses GNU Octave.
Built parallel to octive-lean. Goals:
- Working Go interpreter for a useful subset (start: pure Go, no goroutines).
- Formal semantics layered on top:
BigStep/PureEval/ValueEquivso proofs about Go programs are first-class. - Cross-language layer — once both this and
octive-leanhave a real evaluator and big-step semantics, factor a shared core out of two concrete points rather than guessing the abstraction in advance.
Build
lake build
Requires the Lean toolchain pinned in lean-toolchain. elan will pick it up automatically.
Run
# REPL stub
lake exe golang-lean
# Run a .go script (not yet implemented)
lake exe golang-lean path/to/script.go
# Verify the corpus against expected outputs
lake build corpus-check
lake exe corpus-check
Layout
| Path | What's there |
|---|---|
GolangLean/ |
Library: Token, Scanner, AST, Parser, Value, Env, Eval, Builtins, REPL, BigStep, PureEval, ValueEquiv, Error |
Main.lean |
Entry point — REPL or file runner |
CorpusCheck.lean |
Test driver for corpus/ |
corpus/ |
.go test cases paired with .expected outputs |
go-upstream/ |
Shallow clone of golang/go (gitignored, used as reference) |
Status
Scaffold. Module skeleton in place. Token and AST are real ports of go/token and go/ast. Scanner / Parser / Eval are stubs that throw notImpl so the project compiles.
Next:
- Implement
Scanner.scanagainstgo-upstream/src/go/scanner/scanner.go. - Implement
Parser.parseFilerecursive-descent againstgo-upstream/src/go/parser/parser.go. - Implement
Evalfor the pure subset (no goroutines, no defer, no panic/recover). - Mirror octive-lean's
BigStep/ValueEquivtriple.
Reference
go-upstream/ is a shallow clone of https://github.com/golang/go. Key paths:
| Path | What's there |
|---|---|
go-upstream/src/go/token/ |
Token kinds, position tracking |
go-upstream/src/go/scanner/ |
Lexer |
go-upstream/src/go/ast/ |
AST node types |
go-upstream/src/go/parser/ |
Recursive-descent parser |
go-upstream/src/go/types/ |
Type-checker (later) |
go-upstream/src/runtime/ |
Runtime / scheduler / GC (much later) |