Daniel Connelly

OCaml

Since moving to a programming language team, I’ve decided I should also learn more about implementation and theory. Last year I read through Crafting Interpreters and Writing an Interpreter in Go, which gave me more insight for writing a few small interpreters and a compiler, but I’d like to go a bit deeper into advanced techniques and theory. So I picked up Modern Compiler Implementation in ML for the former and Types and Programming Languages for the latter. I don’t know any ML, and while I spent most of January learning Rust (I re-implemented about a third of Advent of Code and wrote the above bytecode compiler) and think it’s a brilliant and incredibly well-designed language and ecosystem, it seems like learning an ML and going even further in the functional direction will be helpful for both working through these books as well as understanding the functional paradigm.

So far all I’ve done is skimmed through a very nice online textbook from Cornell and started working through Advent of Code again while writing a small interpreter. The language feels both powerful as well as incredibly concise. For example, here’s my implementation of the entire Intcode virtual machine used throughout the 2019 Advent of Code:

For comparison, my Rust version is about 3x as long. There are some differences in the implementations, but in general it’s amazing how concise the OCaml implementation is, and how little difference it made in the performance to use immutable/persistent data structures and no mutation.

(Full OCaml solutions are here)

I’m still working on the interpreter, and I’d like to get through several more Advent of Code problems again before moving on to the compiler book, but I’m really loving OCaml so far.