HeadlinesBriefing favicon HeadlinesBriefing.com

Inside Little Functional Languages: From Strict to Lazy

Hacker News •
×

Functional language enthusiasts often wonder what separates the tiny Haskell-like languages from each other. Ben Lynn's MicroHs and Newt showcase different approaches to compilation and bootstrapping. The core phases remain consistent: lexing, parsing, desugaring, type inference, pattern matching, normalization, optimization, closure conversion, code generation, and runtime systems.

A fundamental divide exists between strict and lazy evaluation. Strict languages like OCaml evaluate arguments before function calls, while lazy languages like Haskell delay evaluation until needed. This impacts everything from closure conversion to memory management. Strict evaluation simplifies debugging and runtime complexity, while lazy evaluation enables infinite data structures but requires sophisticated thunks and update frames.

Bootstrapping versus hosted compilation represents another critical choice. Self-hosted compilers like MicroHs compile themselves using only a C compiler, while hosted compilers rely on existing language ecosystems. The bootstrapping approach, exemplified by Ben Lynn's staged compilation from C runtime to near-Haskell-98, creates self-sustaining languages. Interpreted implementations skip compilation entirely for simplicity, while native compilation delivers maximum performance at the cost of significant complexity in register allocation and calling conventions.