I’m working on a compiler this morning which is part of my academic research. The front end is built in OCaml, the back end is LLVM.
The language itself is intended to be a fully safe C-like language, but unlike the other 250 attempts at building such things (say, Cyclone), the goal is to have a language which is not only at first glance almost C (to facilitate easy incremental conversion of existing code), but is almost fully ABI and API compatible with C (to facilitate easy incremental conversion of existing code). The details of how I’m doing this are almost certainly beyond the scope of this thread. (Also, as academic research, the odds that anyone else will ever use this thing are slim, so the details probably matter only to people reading my papers. )
Working in OCaml has been quite pleasant and very very productive. I’m a very new OCaml’er, but I’m finding the language almost relaxing to work in. It’s rare that I’ve had this “it’s soothing to use” experience in other languages. (A few others come to mind over the years: a couple of Lisp dialects, and (oddly) Ruby.) I also managed to get up to speed in the language very very fast, it was only a matter of a couple of weeks. I’m still rusty on a lot of edge conditions and not 100% comfortable but it’s working out quite well.
As long as I’m new and still have these things in my head, I might mention what’s been bad. I should emphasize, nearly everything has been good, from the readability of the language, to the ease of asking questions of the OCaml community, to the quality of the available Emacs editing modes (tuareg+merlin is a fantastic help!) But of course, nothing is ever perfect, and a couple of things have been rough.
One major impediment to my work has been poor documentation. Of course, the bad LLVM documentation has set me back far more than the bad OCaml documentation. (The OCaml documentation isn’t nearly as bad as the LLVM docs, which are truly appalling.)
That said, if you compare the library documentation of OCaml with other systems (say, the C library man pages in BSD Unix, the Common Lisp Hyperspec, or the online library documentation for Python or Ruby), it’s a little on the sad side. It desperately needs improvement. If one wants to claim to be a modern, industrial strength language, one needs modern, and even for psychological reasons modern looking, documentation. (The CL hyperspec is even less modern looking of course.)
However!: there are good OCaml books, and the OCaml language manual isn’t too bad. Also, the OCaml community is great at helping people when they ask for assistance, for which I’m very grateful. (In LLVM world, if you ask a basic question, it can go unanswered forever. In the OCaml community, someone will always help you out.) I’m starting to really love the OCaml community, which is almost as good a feature of the system as the language itself.
A second pain point for me has been OCaml’s, er, plethora of overly opaque build systems. A newcomer unfortunately cannot avoid dealing with a build system almost as soon as they start working, because they need to compile their code, so they can’t avoid having to figure out how to build things.
One problem with the OCaml-centric build systems I’ve touched so far is that the documentation has too much of a “just use these magic commands and don’t worry too much about what they mean” flavor. Unfortunately, I’m perhaps too old a programmer to willingly turn off the “how does that work!?” part of my mind, it desperately wants to understand the semantic content of commands I’m using. The documentation for the various build systems is also quite weak.
So as a result, I’ve been limping along with really, really horrid Makefiles I’ve been constructing by hand. They’re terrible, but I understand what every line means, and when I’ve tried working with the other stuff I haven’t had that grasp on what a given line meant.
At some point soon, though, I’m going to have to bite the bullet and try to use something like jbuilder. I must confess I’m not looking forward to this because it felt too much like magic and too little like something I could understand and control, but that might be entirely my own fault for not spending more hours trying to understand it better.
Anyway, looking forward to another productive week of coding in OCaml. So far the experience has been absolutely terrific!