HeadlinesBriefing favicon HeadlinesBriefing.com

Tiny ML Compilers: How Small Can Functional Languages Get?

Hacker News •
×

A comprehensive survey of minimal ML-style language implementations reveals just how compact functional programming can be. From Hirrolot's Calculus of Constructions in ~70 lines of OCaml to Harrop MiniML compiling to native code in ~100 lines, these tiny compilers demonstrate the core of functional language design. The collection spans everything from basic lambda calculus to full Hindley-Milner type inference and algebraic data types.

Algorithm W Step by Step provides the canonical ~300-line Haskell implementation of Hindley-Milner type inference, while THIH (Typing Haskell in Haskell) packs Haskell 98's complete type system into just 429 lines. Other notable implementations include tomprimozic/type-systems with row polymorphism variants and various interpreters ranging from ~500 to ~15,000 lines. The survey covers essential features like integer arithmetic, closures, pattern matching, and garbage collection, with specific line counts for each capability.

The resource serves as both inspiration and practical guide for language implementers. With complete implementations of template instantiation, G-Machine, and Zinc abstract machine available, plus the Elaboration Zoo for dependent types, aspiring compiler writers have everything needed to build their own functional language. Whether targeting LLVM, x86, or WebAssembly, these tiny implementations prove that sophisticated type systems need not require massive codebases.