Building a Z‑Machine in the worst possible language

April 12, 2026
A detailed close-up of a vintage mechanical typewriter, showcasing the type bars and strikers.
Photo by Arturo Añez. on Pexels

The weird bet

The Z‑machine is a bit of software archaeology — Infocom’s 1980s virtual machine that let text adventures run everywhere. So when a developer decided to reimplement it, they didn’t reach for C or Rust. Instead, they picked Elm: a pure, immutable, side‑effect‑free language that, on paper, seems tailor‑made to make a byte‑level VM miserable. Who thinks, “Yep, that’s the right tool”? Apparently somebody did. It’s a deliciously contrarian choice, and the result is equal parts nostalgia and homage.

How the puzzle was solved

The obvious problem is mutation. A Z‑machine expects direct memory writes and a mutable stack; Elm gives you persistent data structures. The clever bit: Elm’s Arrays are implemented with an RRB‑trie variant under the hood, which drastically reduces the cost of creating modified copies. That turned what looked like a performance disaster into something workable. It has been reported that after wrestling with text encodings and immutable patterns, the author produced a running Z‑machine capable of loading a .z3 Infocom game and allegedly passing the Czech compliance test for Z‑machines.

What this actually looks like

The project isn’t just a proof of concept. The interface is tidy: ZMachine.load : Bytes -> Result String ZMachine loads a game in one line, and ZMachine.runSteps : Int -> ZMachine -> StepResult runs a bounded number of instructions and returns rich results — Continue, NeedInput, NeedSave, NeedRestore, Halted or Error — along with output events and an updated machine. That design makes it practical to embed a player in the browser and experiment with front‑end UI ideas (the author specifically mentions things like an “if‑pal” client experiment). So yes, you can be nostalgic and modern at once.

This is the kind of project that makes you smile if you love odd technical challenges. The real kicker is the emotional pivot: initial doubt, followed by that joyful surprise when the immutable world turns out to be flexible enough after all. It’s a neat reminder that sometimes the “worst” tool for the job teaches you something new — and, if nothing else, gives you a great story to tell.

Sources: whitebeard.blog, Hacker News