
Ask HN: What makes OCaml so desired for writing compilers? - hellofunk
From what I understand, the original Rust compiler as well as Facebook&#x27;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?
======
SamReidHughes
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.

~~~
hellofunk
> 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.

~~~
SamReidHughes
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](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.

------
feklar
For all these reasons: [http://flint.cs.yale.edu/cs421/case-for-
ml.html](http://flint.cs.yale.edu/cs421/case-for-ml.html)

Many school courses use ML/OCaml as well in their classes and as you do the
course they explain why OCaml/ML is best suited for what's going on
[https://www.cs.cmu.edu/~fp/courses/15411-f13/schedule.html](https://www.cs.cmu.edu/~fp/courses/15411-f13/schedule.html)

