Killer use-cases (tools, libraries, domains, etc) for OCaml

I wanted to ask all of you to share your thoughts on what are the killer use-cases for OCaml today (think along the lines of Rails for Ruby, systems programming for Rust, data science for Python, etc). Basically I want us to discuss the type of problems for which OCaml is a great fit and the tools (e.g. libraries, frameworks, etc) that go hand-in-hand with the respective problem spaces. E.g. one can say that OCaml is a great option for building parsers because of Menhir and so on.

In a way the topic is similar to the recent topic about favorite libraries (see Top 5 Favorite OCaml Libraries? - #17 by arno), but I’ve noticed most people there mentioned just basic libraries, which don’t really help to understand how are they actually using OCaml and what do they consider its strongest areas.

3 Likes

A few Proof Assistants are written with OCaml


The Carnegie Mellon University Binary Analysis Platform (CMU BAP) is a suite of utilities and libraries that enables analysis of programs in the machine code representation.

1 Like

Symbolic computation (compilers, interpreters, DSLs, etc) is OCaml’s “traditional” bread and butter, but at LexiFi we use OCaml for everything from web frontends (via js_of_ocaml), to server backend (databases, web servers), native UIs, high performance numeric code, etc; in our experience OCaml is an excellent choice for each one of these. I shudder when I think about maintaining (not so much implementing) this code in more “popular” languages.

Cheers,
Nicolas

4 Likes

Obviously: the historical strengths are compilers, proof assistants, automated theorem provers :-). In general I’d say it’s great for reasonably fast implementations of complex algorithms.

2 Likes

In the engineering/data science domain I use OCaml to deal with unstructered (measurement) data, e.g., parsing logfiles, import/export from device specific databases, and controlling of test equipment. The range is from small script-like tools to convert data to complete desktop applications to run production tests in an assembly line (incl. GUI, controlling test equipment, and database storage).

OCaml’s strength here is the support for robust tools that rarely show undefined behavior in case of unexpected input data. Applications usually run everyday without errors/crashes.
Also, extending and refactoring for changed or extended requirements hardly breaks existing funcionality.
This is probably due to the strong type system and functional paradigm, and the high quality of compiler/build tools and libraries.

OCaml’s weak points are the perception as an exotic programming language which makes it harder to gain acceptance in other software teams and the development experience on Windows. The main “competitors” in the described fields are Python and C#/.NET (I am working in a Windows-centric company).

According to the described use cases, the following libs are on my top list:

2 Likes

That’s a huge range of applications with OCaml!

I don’t ever do work related to hardware. How do you actually “[control] test equipment” with OCaml? Is there a assembly/c api that you use and wrap OCaml over?

To add to that, Facebook uses OCaml for Hacklang type-checking, Flow type-checking, and their pfff analyzer.

Oh, pfff is discontinued, I see now. The other two should still be used. And apparently they made a Python analyzer too.

Yes, usually the test equipment supplier provides a C-api for their instruments. With OCaml‘s C-api it is easy to write bindings for that, sometimes with the help of the ctypes library. There is also a communication/driver standard called VISA that can be used for different instruments (and therefore can reuse generated OCaml bindings for it)

1 Like

Meta’s Infer is too implemented in OCaml https://fbinfer.com/ But this is still the same symbolic computation area.

From my experience, OCaml is a good general purpose language. It has a reputation of being esoteric, but in fact it’s much more straightforward than, say, Haskell. However, the ecosystem is historically much more tuned to compilers, static analysis tools, etc.

Although, there are libraries for web and whatnot, I feel when it comes to running stuff in prod it’s less mature than what you’d find e.g. on the JVM.

1 Like