Staying up to speed with OCaml in the year 2021

I’ve used OCaml about ten years ago for fractal rendering (example here) and while I had some issues with it, mostly lack of operator overloading and a somewhat paltry ecosystem, it was mostly a decent experience. I’ve been looking into F# as well but since I think the optimal experience for that is on Windows (which I don’t have installed) even though .NET Core is pretty straightforward, so I’m looking at OCaml again.

I’ve followed the instructions here although updated with the latest version:

Important stuff that stands out already: core (batteries is pretty much dead yeah?), utop, dune, merlin. I have merlin set up with Vim and I believe it works with YCM.

What else is a must have for today’s OCaml developer and what are the best resources for (re-)learning the language? A lot of material I found seems pretty old but maybe the language standard is just quite stable.

2 Likes

From what I understand Batteries has been releasing steadily. There is also the Containers library which is highly regarded. And the dark horse in the race … the OCaml standard library, i.e. Stdlib. It has been steadily getting more more fleshed-out after being renamed from Pervasives and rearranged a bit. I would even go as far as to say that it’s a must-have for today’s OCaml developer :slight_smile:

6 Likes

VS Code with the OCaml Platform plugin paired with the OCaml LSP server is what I would suggest even though vim + merlin is a powerful combo. You might also want to checkout Real World OCaml. Just in case you’re not familiar Opam is great for managing the compiler installation as well as any libraries you’re using.

3 Likes

Batteries is stable and continues to be maintained with regular releases. Like many mature projects, development has slowed and they certainly would welcome more contributors. @UnixJunkie just did a presentation last month on Batteries at the Houston Functional Programming User Group, which included a comparison of the advantages and disadvantages of OCaml’s various alternative stdlibs. Slides from his presentation are at https://hfpug.org/2021/01/21/francois-berenger-ocaml-batteries-included/

5 Likes

No, batteries is not dead. It is actively maintained:

We might even name the next release “phenix”.
Because the phenix never dies. :smiley:

5 Likes

ocp-browser and ocp-indent are cool too.
opam is a must have, as mentioned by others.

1 Like

what you definitively need, are some :camel: stickers on you laptop lid or office door. :slight_smile:

4 Likes
  • I can recommend tuareg-mode in emacs (I use doom-emacs with vim bindings) for a lovely IDE experience (bonus points for steering clear of Microsoft’s growing monopoly on dev tooling).
  • Check What are some libraries you almost always use? - #18 by mjambon for some great library recommendations (my most used libs recently are Bos (including Rresult and Fpath that come along with open Bos_setup), Cmdliner, and ppx_jane).
  • Expect testing (using ppx_expect, included in ppx_jane) and the cram-style testing supported by mdx and dune are really lovely, and afaik pretty unique the ocaml ecosystem? Inline testing is also nice (via ppx_inline_tests).
  • I reach for qcheck for any nontrivial testing.
  • ppx_deriving is great when need to serialize/deserialize or derive basic functions on your data structures.
  • I have not yet used it myself, but drom is worth a look for expediting project setup and management!
5 Likes

Some of the best learning resources I’ve enjoyed (aside from simply reading the language reference) have been from years- or decades-old works.

I think Xavier linked to this recently somewhere on this forum, but here is a paper describing how a team recovered the sources for and reproduced results from a notable parallel programming system implemented in OCaml, targeting v1.07, originally released some 20+ years ago: [Rp] Reproducing and replicating the OCamlP3l experiment - Archive ouverte HAL

A relevant quote:

To our great surprise, and satisfaction, the code compiled with the modern OCaml 4.05 installed on our machines unchanged. The only notable difference is that the modern compiler produces several new warnings that correspond to better static analysis checks introduced over the past quarter of a century.

So, enjoy those older reference materials. :smiley:

7 Likes

ocp-indent is nice but I’ve come to prefer ocamlformat even though I don’t necessarily agree with the defaults. I personally prefer a more vertical style as it allows for better diffing, something along the lines of:

break-cases = fit-or-vertical
break-infix = fit-or-vertical
break-fun-decl = fit-or-vertical
type-decl = sparse
4 Likes

I think you mean “phoenix”.

1 Like

In french we write “phénix”, or in old style “phœnix”.

1 Like

I use Vim with Ocaml LSP server and ocamlformat and it was surprisingly easy to set up. One annoyance is that I have to run dune build in the terminal if I want to propagate module changes across files.

1 Like

@readyready15728 it could be helpful to take a look at Ocamlverse.

2 Likes