OCaml’s static typing allows it to detect many problems at compile-time. Still, some bugs slip though. In this post, I go over each discovered bug that made it into a Git commit and try to work out why it happened and whether it could have been prevented.

OCaml makes heavy use of parametric polymorphism (which you may also know as “generics” in other languages).
The OCaml tutorials mention it from time to time, but the information is spread about over many articles and they don’t go into much detail.
I’m not a type theorist, just a Python/Java/C programmer who finds this stuff interesting.
I wanted to write this guide while I still remember the things that confused me.
I know several OCaml experts keep an eye on this blog, so hopefully any inaccuracies will be corrected in the comments.

I’ve now migrated the asynchronous download logic in 0install from Python to OCaml + Lwt.
This post records my experiences using Lwt, plus some comparisons with Python’s coroutines.
As usual, the examples will be based on the real-world case of 0install, rather than on idealised text-book examples.

the relation between object, class and type in OCaml is very different from that in mainstream object-oriented languages like Java or C++, so that you should not assume that similar keywords mean the same thing.

Good advice. Coming from a Python/Java background, here are some surprising things about objects in OCaml:

After we selected OCaml as the new language for 0install, I’ve been steadily converting the old Python code across. We now have more than 10,000 lines of OCaml, so I thought it’s time to share what I’ve learnt.

OCaml is actually a pretty small language. Once you’ve read the short tutorials you know most of the language. However, I did skip one interesting feature during my first attempts:

There are also “polymorphic variants” which allow the same field name to be used in different structures, but I haven’t tried using them.

I’ve since found a good use for these for handling command-line options…

In the initial language analysis, OCaml did well in most areas except for diagnostics (which turned out to have an easy solution) and shared libraries / binary compatibility. Now it’s time to look for a solution to that.

In the first post, I took a brief look at the programming
languages ATS, C#, Go, Haskell, OCaml, Python and Rust to try to decide which would be the best language in which to write 0install (which is currently implemented in Python). Now it’s time to eliminate a few candidates and look in more detail at the others.

Last time, I converted 4 lines of Python code from 0install into each language. This time I’m converting 576 lines, so this should
give a more accurate picture of how each performs for a real-world task.

This post evaluates the programming languages ATS, C#, Go, Haskell, OCaml, Python and Rust to try to decide which would be the best language in which to write 0install (which is currently implemented in Python). Hopefully it will also be interesting to anyone curious about these languages.

I’m not an expert in these languages (except Python). My test-case is to read the tutorial for each language and reimplement one trivial function of 0install in the language. These languages were suggested by various people on the 0install mailing list. If I’ve got anything wrong, please add a comment.