{"slug": "puffin-scheme-like-language-with-self-hosting-compiler-and-gradual-types", "title": "Puffin: Scheme-like language with self-hosting compiler and gradual types", "summary": "Kristopher Micinski and Claude Code have created Puffin, a minimal Scheme/ML-like functional programming language with a self-hosting compiler, gradual types, and three backends (arm64, x86-64, bytecode). The compiler, puffincc, is written in Puffin itself and can bootstrap from a bytecode seed using only a C toolchain, with a goal to replace Racket for day-to-day compiler and interpreter development. The language includes match patterns, quasiquoting, a gradual type system, a typed FFI, modules, and a standard library, though the author notes serious gaps in gradual typing and module design.", "body_md": "Puffin is a minimal Scheme/ML-like functional programming language\nwritten by Claude Code, directed by (and extending a compiler written\nby) Kristopher Micinski. The original compiler / language is detailed\nhere:\n[https://kmicinski.com/functional-programming/2025/11/23/build-a-language/](https://kmicinski.com/functional-programming/2025/11/23/build-a-language/)\nI used Claude Code to build Puffin by extending that teaching-focused\nlanguage (from Jeremy Siek's compiler book) with several\nquality-of-life features:\n\n- Match patterns and quasiquoting\n- A gradual type system using consistency-based typing\n- A simple standard library consisting of sets, hashes (dictionaries), and several other facilities\n- A simple module system inspired by SML\n- A typed FFI\n\nThe project is, in some ways, an adventure in Slop. My ultimate goal is to use this to replace Racket for my day-to-day brainstorming in compiler / interpreters / etc. Claude Fable built the code, I read all of the code and understand the compiler's structure--but there are still some serious gaps which have not been fully thought-through: gradual typing, modules, these are places which are seriously prototypical so far. I have written (again, using Claude Code) some large ports of Racket applications into Puffin, and a translation of a large (~10kloc) Racket application did demonstrate a serious Puffin compiler bug--so there are surely both (a) genuinely bad, unsound design choices which must be rooted out and (b) bugs in the implementation.\n\nHere's a \"hello world\" example:\n\n```\n(define-type Expr\n  (Num Int)\n  (Add Expr Expr)\n  (Mul Expr Expr))\n\n(define (eval-expr [e : Expr]) : Int\n  (match e\n    [(Num n) n]\n    [(Add a b) (+ (eval-expr a) (eval-expr b))]\n    [(Mul a b) (* (eval-expr a) (eval-expr b))]))\n\n(println (eval-expr (Add (Mul (Num 3) (Num 4)) (Num 1))))   ;; 13\n```\n\n**The compiler is called puffincc**: it is self-hosting, written in\nPuffin (see\n\n`puffincc-src/`\n\n), and includes with three backends: (a)\narm64, (b) x86-64, and (c) bytecode. It is the single source of ground\ntruth for the language: the browser playground (`web/`\n\n) runs *puffincc itself*, compiled to bytecode, on a WebAssembly build of the bytecode VM (\n\n`src/vm/`\n\n).Some highlights coming from Racket:\n\n**Self-hosting, Racket-free**:`bin/bootstrap`\n\nbuilds the compiler from the committed bytecode seed with nothing but a minimal C toolchain (why not Rust!?), and should yield a stage-2/3 byte-identical fixpoint every time.**Gradual types** are described in`docs/TYPES.md`\n\n: ADTs, annotations where you want them,`_`\n\nwhere you don't; transient casts with blame at declared boundaries; exhaustiveness warnings.**A typed FFI**(`docs/FFI.md`\n\n):`dlopen`\n\n'd C imports declared with ordinary`(: name τ)`\n\ntypes; the declaration generates the marshaling, and every crossing is checked with blame naming the import. As an example,`examples/z3/`\n\nbinds the Z3 SMT solver as a Puffin API.**Modules + separate compilation** described in`docs/MODULES.md`\n\n, a native REPL, a bytecode VM, and the in-browser playground with the real compiler and REPL.**Tested by construction**: a 309-check golden corpus and a differential*error*corpus run every program down every route — diagnostics byte-identical, rejection behavior corpus-tested like success.\n\n[Quick start](#quick-start)\n\n```\nbin/bootstrap                       # Racket-free bootstrap: cc-only, from\n                                    # the committed seed boot/puffincc.pbc,\n                                    # with a stage-2/3 fixpoint proof\nbuild/puffincc prog.puf -o prog     # puffincc compiles + links natively\nbuild/puffincc -t bytecode prog.puf -o prog.pbc   # ... or to bytecode\nbin/puffin-vm prog.pbc              # run bytecode on the native VM\ntools/test-corpus.sh                # the golden corpus, Racket-free\n                                    # (`gen` mode WRITES the goldens)\ntools/test-errors.sh                # the differential ERROR corpus\n                                    # (src/errors-corpus): must-fail\n                                    # programs x every route\ntools/test-examples.sh              # the examples/ programs vs their\n                                    # goldens, native + VM (z3 examples\n                                    # skip when libz3 is absent)\ntools/gen-web-vm.sh                 # browser engine artifacts (self-hosted)\n(cd web && npm run dev)             # the playground: puffincc in wasm\nbin/refresh-boot                    # refresh the seed at release points\n```\n\nMulti-file programs use the module system (`(require \"lib.puf\")`\n\n/\n`(provide ...)`\n\n); all backends (native, the bytecode VM, the web\nplayground) resolve via puffincc's resolver.\n\n[Documentation](#documentation)\n\nThere is a tutorial here:\n[docs/tutorial.html](docs/tutorial.html), *Puffin for Racketeers*. We (me and mister Claude) also wrote reference docs:\n\n[docs/LANGUAGE.md](docs/LANGUAGE.html)— the language, day to day[docs/TYPES.md](docs/TYPES.html)— the gradual type system[docs/MODULES.md](docs/MODULES.html)— modules and separate compilation[docs/FFI.md](docs/FFI.html)— the FFI, with runnable[examples/](examples/index.html)(including the Z3 binding and a solve-and-prove-unique Sudoku)[docs/STDLIB.md](docs/stdlib-overview.html)— the standard library (docs/stdlib.html is the generated reference; its examples are executed and asserted at generation time)[docs/OPTIMIZER.md](docs/OPTIMIZER.html)—`-O 0|1|2`\n\n[docs/WASM-VM.md](docs/WASM-VM.html)+[docs/BYTECODE.md](docs/BYTECODE.html)— the VM and the browser architecture[docs/BOOTSTRAP.md](docs/BOOTSTRAP.html)— how the Racket-free bootstrap works[docs/DELTA.md](docs/DELTA.html)— the project's history: \"what's the delta from the course compiler?\"\n\n[The Racket oracle](#the-racket-oracle)\n\nThe Racket implementation in `src/`\n\nis the optional **consistency\noracle**: it cross-checks puffincc per-pass (`src/diff-ir.rkt`\n\n), and\nits reference interpreter re-derives the goldens as a differential\ntest: the two implementations must agree byte-for-byte.\n\n```\nbin/build-puffincc                  # hosted stage-1 bootstrap (alternative)\nbin/puffin                          # the Racket-hosted CLI/REPL\nracket src/test.rkt -m all          # the corpus through the oracle routes\nracket src/diff-ir.rkt <pass> <prog>  # per-pass puffincc/Racket diff\n(cd web && npm test)                # corpus + REPL through the wasm VM\nnode web/test-errors.mjs            # the error corpus through the wasm VM\n```\n\n", "url": "https://wpnews.pro/news/puffin-scheme-like-language-with-self-hosting-compiler-and-gradual-types", "canonical_source": "https://kmicinski.com/puffin-lang/index.html", "published_at": "2026-07-22 20:09:36+00:00", "updated_at": "2026-07-22 20:22:26.681428+00:00", "lang": "en", "topics": ["artificial-intelligence", "developer-tools"], "entities": ["Kristopher Micinski", "Claude Code", "Puffin", "puffincc", "Racket", "Z3", "Jeremy Siek"], "alternates": {"html": "https://wpnews.pro/news/puffin-scheme-like-language-with-self-hosting-compiler-and-gradual-types", "markdown": "https://wpnews.pro/news/puffin-scheme-like-language-with-self-hosting-compiler-and-gradual-types.md", "text": "https://wpnews.pro/news/puffin-scheme-like-language-with-self-hosting-compiler-and-gradual-types.txt", "jsonld": "https://wpnews.pro/news/puffin-scheme-like-language-with-self-hosting-compiler-and-gradual-types.jsonld"}}