Ask HN: What makes OCaml so desired for writing compilers?

5 points by hellofunk ↗ HN
From what I understand, the original Rust compiler as well as Facebook's current Hack PHP compiler were written in OCaml. There are several static, functional languages out there, what makes OCaml more suited than other languages for compiler design and implementation? What are the features desired for writing a compiler?

4 comments

[ 3.5 ms ] story [ 23.1 ms ] thread
The most important factor is that it's easy to define types and use them, especially variants or tagged unions, whatever you want to call them. In languages like Java, defining a new type is a huge exercise in bureaucracy, and it's even worse for a variant. It's also important that it's natively compiled, impure and strictly evaluated, because performance matters. It also has a lot of other features that we take for granted nowadays.

Nowadays there are a lot of options that would be just as good, or better.

> Nowadays there are a lot of options that would be just as good, or better.

Would like to know what you think they are, because new efforts by major companies are still using OCaml for lots of things, including the design and and implementation of new languages.

Swift, Scala. Or even, dare I say it on this website, Rust?

One thing I didn't think about, though, was portability: https://ocaml.org/learn/portability.html

So I'm guessing Swift isn't there yet, and Scala has the ick of a JVM -- it looks like OCaml is easier to get going on a new platform if you have a C compiler.