Cover image for How To Learn OCaml

How To Learn OCaml

sophiabrandt profile image Sophia Brandt Originally published at rockyourcode.com on ・3 min read

A starting point for learning OCaml - a functional, type-safe, expressive, and battle-proven language

Why OCaml?

OCaml is an open-source functional, statically typed, and mature language. If you want to learn such a paradigm, OCaml is far more beginner-friendly than Haskell.

OCaml has a blazingly fast compiler and excellent type inference. It offers exhaustive pattern-matching, which makes your programs concise and a joy to work with.

I've come to OCaml from ReasonML, a JavaScript-like syntax, and tool-chain for OCaml.

But as ReasonML is OCaml, you should know how OCaml works.

This guide is for people who already know at least one programming language, not for total beginners.

Beginner's Guide to OCaml Books

Start by reading the blog post by Alex Clemmer. It provides an overview of novice-friendly books and tools.

To make it short, he recommends Real World OCaml (free HTML version) and OCaml from the Very Beginning.

OCaml Website

The official website has a dedicated section for learning resources.

Cornell's Book for Course 3110 (Learning a Language)

(edit: Michael Kohl pointed this one out to me.)

The free text book covers a variety of topic concerning functional programming, and OCaml.

A Practical Approach

To get started quickly, read the OCaml section of Learn X in Y minutes to get the big picture.

Then head over to the Jane Street OCaml Workshop and clone their repository.

Check out Shawn Wang's Ocaml Speedrun! blog post on dev.to for solutions to the workshop.

Install OCaml and OPAM, install Dune (via Opam), and go through the workshop.

Supplement your learnings by reading the books mentioned above or by going through the free MOOC Introduction to Functional Programming in OCaml.

Exercism.io also offers an OCaml track.

Editor Tools

OCaml uses Opam for package management. You have to install it and then run the following command from your terminal:

opam init

VS Code comes with several plugins for OCaml.

reason-vscode should suffice for most use cases. It comes with a built-in language server that offers autocomplete, hover information, and more.

Make sure to use a compatible OCaml version. The latest Ocaml version (4.09.0) doesn't work yet; you have to downgrade to 4.07.0.

I've found a guide for VS Code and Ocaml from 2018, which could be useful.

If you use Vim, Merlin provides a better experience.

I'll write a guide about my setup with NeoVim soon.


Posted on by:

sophiabrandt profile

Sophia Brandt


tax officer who codes in her spare time https://www.rockyourcode.com 🎸🎶


Editor guide

Let me offer one more resource, Learning a Language, a text book for Cornell's CS 3110 course which uses OCaml. Also while originally developed for Reason, esy slowly seems to be gaining some traction in the OCaml community too, or at least in my Twitter bubble.


Thank you very much, Michael! That looks like a concise tour on OCaml. Very helpful.