An O(x)Caml book that runs · KC Sivaramakrishnan
KC Sivaramakrishnan
© 2008 - 2026. All rights reserved.
KC Sivaramakrishnan<br>Building Functional Systems
An O(x)Caml book that runs
13 Jun 2026<br>I am building a course, “Functional Programming with OCaml”, for the<br>NPTEL<br>MOOC platform: twelve modules, recorded lectures, the works. The<br>course book is not a PDF and<br>not a website with code listings you copy elsewhere. It is a website<br>where the code runs, in your browser, with nothing installed and no<br>server behind it. The first half is<br>OCaml; the last few modules cross into OxCaml. An O(x)Caml book, and<br>one that runs.
This post is about why I built it that way, how I wrote it (with a<br>lot of help from an LLM, under careful review), and the pieces I<br>think are genuinely new.
Zero to OCaml in zero steps
The single biggest obstacle a beginner hits with any language is not<br>a concept. It is the install.
OCaml has gotten much better here over the years. The<br>OCaml Platform extension<br>for VS Code will install a compiler toolchain for you, and the<br>dune build system and the<br>opam package manager have all<br>worked seamlessly together for years now. But that is the experience<br>for someone who already knows they want VS Code, knows what a switch<br>is, and knows what to do when a step does not go as the happy path<br>describes. For a beginner, the path from “I have a laptop” to “I ran<br>my first OCaml program” still has non-trivial steps, and the failure<br>modes are exactly the ones a beginner is least equipped to debug.
I have lost count of the hours spent at the start of hands-on<br>workshops just getting OCaml onto people’s machines.<br>Anil Madhavapeddy once told me that he<br>and Yaron Minsky spent almost the<br>entire session of their<br>2013 CUFP OCaml tutorial<br>getting OCaml installed on attendees’ laptops. I have done my share<br>of the same, walking a room through opam, and more than once<br>apologising for the state of Windows support. That last apology I no<br>longer have to make, thanks to the opam team’s work over the past<br>few years (see the<br>opam 2.2.0 alpha announcement<br>on native Windows). I have had my own forays into fixing the broader<br>problem: OCaml Jupyter notebooks wrapped in a<br>Docker container (I wrote about<br>teaching with Jupyter notebooks<br>years ago, and that is how I taught CS3100), and more recently<br>devcontainers for workshops. The<br>OxCaml ICFP tutorial<br>and our<br>learn-ocaml workshop<br>materials both lean on containers too.
These work, but only in the right setting. In a classroom where<br>people can spend a couple of hours getting dependencies in place,<br>fine. On conference wifi, for a two-hour tutorial, downloading a<br>devcontainer or a Docker image takes all the fun out of programming<br>before any programming has happened.
What I wanted was zero to OCaml in zero steps. No install. And, just<br>as importantly, no servers for me to administer. But still a seamless<br>experience where a learner can change code and execute it.
You are reading the book right now, in a sense. Here is a live cell.<br>If you are in a browser, there is a Run button near the top right.<br>Click it. Change "reader" to your own name and run it again.
let greeting who = "hello, " ^ who<br>let () = print_endline (greeting "reader")
The OCaml toplevel just ran in your browser. No server, no install,<br>and the bytes never left your machine.
Why purely client side
The best thing about programming is that you can poke at it: change<br>something, watch how it reacts, and learn from the reaction. Books<br>cannot be poked. The usual fix is to read with an editor open<br>alongside and type things in, but that always feels slightly off,<br>because the book cannot assume you are playing along. It has no way<br>to know you have the same compiler version, the same libraries, the<br>same anything, so the interactive part drifts out of sync with the<br>prose. I wanted the opposite: a book that assumes you are playing<br>with it, because the playground is built into the page.
Where this course lives makes that assumption load-bearing. NPTEL is<br>a MOOC; I never meet the students and there are no dedicated labs. A<br>student might be on a laptop shared with a parent, on Windows 11, on<br>a tablet with an external keyboard, or on some machine you would not<br>expect to still be in use and that OCaml very likely does not<br>support. Around 170 people have enrolled so far, and I do not want a<br>single one of them to give up on OCaml over an installation problem<br>in the first hour.
So the book is purely client side. The website is the textbook:
There is no separate textbook to buy or download. Every lecture in<br>this course is also a page on the course website, and the slides<br>you see in the videos are excerpts from those pages. The website is<br>the book: the same material, expanded into prose, with the examples<br>runnable in place and the quizzes interactive. Open it in any<br>browser; no login, no install, nothing to download.
None of the individual pieces are new. Running OCaml in the browser<br>has been possible for years: the...