Compiling gracefully
summary
Derives a small Haskell-to-stack-VM compiler by treating stack computation as functions on (accumulator, stack) and solving category homomorphism equations so definitions fall out algebraically. Uses Control.Arrow-style first/second/cross laws, monoidal/cartesian structure, parametricity and GADTs to reify stack programs into a concrete interpreter. Produces explicit stack instructions (push/pop, swap, assoc) and an interpreter from StackProg to StackFun; claims are simpler semantics, static fail-safety, applicability to richly typed Haskell, and a worked implementation described in a draft paper.
AI-written summary · about
chapters (22)
- 0:00Introduction and welcome
- 1:09Revisiting stack machine compilation
- 2:11Denotational design methodology
- 3:37Essential nature of stack computation
- 4:41Stack functions and homomorphisms
- 6:27Category theory as the language
- 9:21Solving homomorphism equations
- 13:54Q&A on stack preservation
- 15:40Type operators in Haskell
- 17:04Sequential composition definition
- 20:11Associative and braided categories
- 21:36Difference between arrow types
- 23:44Definition versus equation
- 26:55Sequential vs stack computation
- 30:05Monoidal categories and stacks
- 33:35Homomorphism for parallel composition
- 36:07Stack operations: push and pop
- 39:38Reflecting on the process
- 40:41Q&A on evaluation and optimization
- 41:47Reifying stack computations
- 44:15Compiler implementation
- 44:56Summary and closing
