jcd.lol

Notes on learning ocaml

I spent the last month or so attempting to learn ocaml. I didn't really succeed, and I am stopping so that I can spend the energy on other projects. I might try to build something with the language at some point but for now I am putting it away, and in all likelihood if I did want to build something it is suited for, I'd reach for rust. Here are some impressions and thoughts from the last month.

From the outside, it seemed attractive. My motivation was to get some experience with a language that was outside the sort that I have the most experience with and that I generally reach for when I am solving a problem. I usually write dynamically typed languages (Clojure, Python), and I thrive with the feedback loop a REPL gives. ocaml would provide strong, expressive types, and the universal top level would hypothetically be a standin for a REPL.

The syntax is ugly. This is, I know, only my opinion, but the soup of operators and forms required to write ocaml just are not attractive. Maybe if I grew more familiar with them they would fade into the background like so many parentheses when I am writing Clojure, but even after a month I find myself getting caught on the rough edges of the syntax.

utop is no replacement for a true REPL. It works, but is clunky, and the required statement ends (;;) make copy pasting code into not as simple as in a lisp REPL. Yes, I can pipe from buffers in emacs, and yes this works, but it feels clunkier than a Clojure REPL.

Dev environment tooling is not great. merlin complains constantly about Base not being recognized even tho I am seemingly pointing the project to the right ocaml version and libraries (sending Base to the utop works fine). I know I could make this work if I needed to, but it would be another time sink and there are other things to do. Indenting doesn't work out of the box with merlin and requires configuration/tweaking. Other similar papercuts take the joy out of writing the language.

The standard library situation is a mess. The first question it seemed like I had to answer starting to learn Ocaml was, Which should I focus on learning, the standard library vs. JaneStreet's Core? I ended up dedicating more time to learning Core, since it seems like it has a more uniform interface, and since the book I chose to work through, Real World Ocaml, used Core. But the fact that there is a choice here is a little off-putting, and speaks to the age of the language and complexity of the ecosystem, and I am not exactly keen on toying with a language where shadowing the standard library is standard practice. For fun, in my spare time. This is again a place where time and effort would smooth things, but without a strong reason to inflict it on myself (like a job or some killer app only available in ocaml) I don't see the point.

The syntax shows its age. I may be biased because I love the austerity and explicitness of lisp, but I found Ocaml's syntax extremely unwelcoming. The way order of operations unfolds means you have to be very careful about which things are wrapped in parens and which are not, and the tangle of operators required to do things like construct match expressions is pretty inelegant. (Again, one person's opinion, but it's the one I have to live with.)

Pattern matching is awesome, and clunky to write (see the issues I mentioned above with dev tooling, especially weird indentation problems).

Option types are frankly awesome and I wish there were a mainstream lisp that made use of them.

The safety ensured by the compiler is very nice. For the right applications, it makes sense. For the vast majority of the things I am likely to write, it is overkill.