Learn Programming with OCaml (new book)

Dear OCaml community,

A long time ago, Sylvain and I wrote a French book on learning programming with OCaml. Recently, the OCaml Software Foundation funded its translation to English. The book is available here:

Learn Programming with OCaml

Many thanks to Urmila for a translation of high quality.

The book is available as a PDF file, under the CC-BY-SA license. The source code for the various programs contained in the book are available for download, under the same license.

The book is structured in two parts. The first part is a tutorial-like introduction to OCaml through 14 small programs, covering many aspects of the language. The second part focuses on fundamental algorithmic concepts, with data structures and algorithms implemented in OCaml. This is also a nice way to learn a language!

The book does not cover all aspects of OCaml. It is ideally complemented by other books on OCaml.

56 Likes

Excellent.

Rem : the link of code.zip seems broken.
“The requested URL was not found on this server.”

Oups… This is fixed. Thanks for reporting it!

This looks like a lovely contribution to the OCaml ecosystem, and programming more generally. I look forward to reading it more closely. Thanks for your efforts here!

1 Like

If its possible, can you please add bookmarks for easier navigation into the PDF?
Thanks!

Done! (@xavierleroy asked for it earlier today :grin: )

3 Likes

This book has grown on me.

It starts by unapologetically digging heavily into mutation, which I disliked at first.

When I started learning OCaml, I was new and quite enamored with FP, and had a bit of a caricature mind set “mutation bad, functional good”.

Since then my view softened somewhat, my preference is still is to try FP first though.

Anyway I enjoyed working through the interesting exercises up to chapter 2 (for now), by comparing and observing the contrast of the different styles one can employ using OCaml (and more).

And FP is introduced incrementally, arguing for its existence etc.

I’ve got quite a bunch of books and this one feels like one of the best “all rounder” on my bookshelf.

I particularly enjoyed the N queens solution, a bit of a :exploding_head: moment for me.

Congrats on the release

4 Likes

Always nice to see a new book (in English) on OCaml!

Is there some GitHub repo or a different place where we can flag errors in the translation, etc? E.g. I’ve noticed on page 11 “Let us now condier some additional details” I guess this was meant to say “Let us consider”.

3 Likes

Another question from the community: Is there any chance that this pdf can be published as EPUB as well? PDFs are hard to read on mobile devices and the fonts do not scale . EPUB is a much more versatile format.

1 Like

Chet (@Chet_Murthy) is already working on making an EPUB version of the book!

5 Likes

Thanks @bbatsov for reporting the typo. Yes, we intend to set up a GitHub repo for readers to report typos and errors. This is on our TODO list (together with nicer web pages :sweat_smile: )

Done: you can now report typos and errors here.

6 Likes

Hi @BearCooder

A preliminary EPUB version of the book is now available. Feedback is most welcome (preferably by submitting an issue here).

Big thanks to @Chet_Murthy who spent weeks working this out from our LaTeX sources.

7 Likes

Thanks so much for this book! I always felt like OCaml was a fairly beginner-friendly language (some compiler messages notwithstanding…), and I’ve been sad that there isn’t much in the way of instructional materials for the novice in English.

I will be happy to recommend this book the next time the subject comes up!

3 Likes

Hi @backtracking,

I clicked the link download the preliminary epub file which downloads as lpo.epub, but in reality I have got a pdf file (called lpo.epub) which is 12 bytes shorter than the pdf file (1979697 versus 1979909 bytes).

Nevertheless, thanks for the book!

Oups, my bad. Apologies. The link is fixed.