HN DigestHacker Newsletter, digested

Issue #809#Books

Learn Programming with OCaml

TL;DR

Sylvain Conchon and Jean-Christophe Filliâtre's French textbook on programming in OCaml is now free in English. Urmila Nair translated it, with funding from the OCaml Software Foundation. It is out under CC BY-SA 4.0, as PDF and EPUB with code. Commenters say it moves too fast for true beginners. Its own introduction aims it at an algorithms course.

The article

Landing page with download links only. The tldr describes the book as the page presents it, and the digest covers the discussion.

The discussion

The thread was friendly toward the book and OCaml, but most of it wandered. The longest branch argued over whether a first language should be an ML or C. It also asked whether C still says anything true about hardware. A second big branch asked why anyone should learn a language at all when LLMs write the code.

ML or C as the first language

The top comment says an ML should be every computer scientist's first language. The C camp answers that C lacks just enough features to force students to learn memory layout, copying and references. Skeptics, citing Chisnall's "C Is Not a Low-level Language", say C's machine model is decades out of date, and one embedded veteran prefers even Fortran. A Paris-Cité teacher describes a middle path, with Java in first year, then C and Caml in second year.

But for a First Language specifically I am in no doubt that an ML should be chosen, and this is despite the fact that the University where I work has taught Java for decades and Python most recently as First Language.

— @tialaramex

C lacks just enough “modern language features”, by design, that students are forced to be vaguely aware of memory layout, memory management, ref vs copy, shallow copy vs deep copy, maybe even calling convention, etc.

— @MeetingsBrowser

Why learn a language when LLMs write code

One reader asked whether learning OCaml still makes sense now that LLMs already know it, and most replies said yes. Some said you cannot steer or check an LLM's code without a mental model of it. Others compared it to kneading dough by hand, which teaches the craft and makes you better with the machine too. A few noted that OCaml jobs were scarce long before LLMs, so people always learned it for the way of thinking.

you are eventually going to have a very bad time if you do not have a solid mental model of the code the LLM is writing, and indeed if you cannot steer the LLM so that its code conforms to your mental models.

— @zem

I still think it worth my time kneading dough by hand. It teaches me the various properties of flour, how external factors like humidity or temperature impact the overall process, and I believe that it makes me a better baker, even when I use a machine

— @aaplok

OCaml as a language for coding agents

Several commenters say LLMs write OCaml better than other languages, thanks to the feedback loop. Global type inference holds the LLM to what it already wrote, compiles are fast, and interface files tell it what each module must do. Rust and Haskell, they said, make the LLM reason about types too much. Asked for evidence, one commenter said they contributed code to an unpublished paper, and that frontier-model token costs limit the study.

Both force the model to reason about types too much. The more constrained type system plus global inference merely holds them to what they already wrote, with very fast feedback.

— @giraffe_lady

OCaml has an idiomatic approach of using interface files for all modules that can be accessed outside their libraries, and interface files give LLMs a great précis of exactly what is wanted.

— @yawaramin

Learning to program in OCaml first

French readers who learned Caml first in prépa or university recall rough opening weeks of type errors, then a payoff. A Haskell-first programmer said functional habits like immutable data and small testable functions stayed for life. Others found the switch from C painful but worth it. Someone noted that OCaml also allows imperative code, so one language can teach several paradigms.

The first few weeks were rough: I did not quite know what a type was and the compiler error messages were unforgiving and hard to understand without that context.

— @nestorD

Is this book for beginners

One reader called the book excellent but too brisk for someone who has never programmed. A reply noted that its introduction targets an algorithms course, so the title oversells it. For newcomers, commenters recommended Cornell's free CS3110 textbook. Others asked whether the 2014 French original had been updated for the translation.

This book, while excellent otherwise, is much too harder for beginners, IMO. The pace is too brisk, and it's far from pedagogically useful if you don't already know how to program.

— @jan_m_savage

Consensus

Learning an ML-family language makes people better programmers, and that still holds when an LLM writes most of the code.

Dissent

The C camp held that a first language should expose memory and copying, which OCaml hides. A few dismissed OCaml outright as strange, with a weak standard library and no Python-sized future.