All languages

MicroHs dialectexperimental

Lennart Augustsson's Haskell compiler: an extended subset of Haskell 2010 translated to SKI combinators and reduced by a small C runtime, so a C compiler is the only build requirement and the whole system fits on a micro-controller.

Overview

MicroHs (also written MicroHaskell) is Lennart Augustsson's compiler for an extended subset of Haskell 2010, translated to combinator graphs rather than native code. It exists so that a functional Haskell toolchain needs only a C compiler to build, and fits on a micro-controller.

Code

-- literals construct; operators consume.
name  = "MicroHs"
year  = 2023 :: Int
greet = s"Hello ${name}, since ${year + 1}"   -- MicroHs string interpolation
half  = 3 / 4 :: Double
One tab per tour slot: literals with operators, algebraic data types with records, a class becoming a dictionary, and lazy recursion as the community idiom. All of it is bracket-abstracted to S, K, and I, so fac reaches the runtime as a graph that the C evaluator reduces — no lambda survives into the object code.

Distinctive traits

  • Combinators are the object code: lambdas become S/K/I, so the runtime is a graph-reduction machine written in C.
  • Bootstrapping without GHC: the compiler is written in MicroHs itself, and generated/mhs.c lets a C compiler rebuild it from scratch.
  • The dialect diverges from GHC: string interpolation and overloaded record access and update are MicroHs syntax, not extensions you opt into.
  • Heap and stack are fixed sizes chosen by runtime flags, which is what makes the micro-controller targets possible.
  • Every supported extension is always on and LANGUAGE pragmas are ignored, so one fixed dialect compiles every module.

Status

Released and maintained, though the package metadata still declares its stability experimental. Hackage carries 0.8 (November 2023) through 0.16 under Apache-2.0, shipping mhs, cpphs, and mcabal; the repository is already at 0.17, with targets spanning Unix, Windows, WebAssembly, and micro-controllers.

Sources & references