I do really wonder what it would be like to learn to program for the first time with OCaml.
I remember learning to use OCaml in a properly functional way after so long writing code in C and it was really miserably painful trying to change how I thought about algorithms. I eventually got over the hill and it changed how I write code in C (for the better?), but I do wonder if it would have been easier to have learned OCaml as a first language instead.
I did so! (quirks of the path I took in the French educational system)
I went through a book similar to the one above, with no internet connection. 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. But, once I grokked the core ideas (a proper idea of what could be done with recursion took much longer), things went surprisingly smooth. I definitely credit it with making me a better programmer.
How old were you?
I started programming at 18 right after highschool (which, I guess, is late by HN standards: a number of my peers had played with Python first and hated Ocaml).
When I first learned to program at university we were taught Haskell. That was 15 years ago and I've not really programmed anything in Haskell since, instead I've racked up years coding professionally in pretty much all the major imperative languages.
I'm aware of why Haskell is not practical as a production language for most companies, but I have to say I've never really coded in anything else that feels as "neat" and it's a shame. Every other language feels like it has some idiosyncratic scaffolding one has to learn, reminding you that you're constrained by how computer hardware works, rather than just expressing an algorithm in terms of inputs and outputs.
I would say it has made me a better coder, I've still kept a preference for keeping data immutable, copyable and abstracting complexity into easily testable functions over classes with unobservable mutable state.
It's a good language to learn programming. Very simple semantics. But ultimately, you need to learn different paradigms, I think the order doesn't matter, they'll still be an element of surprise.
Also OCaml lets you write imperative code if you wish so. So you can learn the different paradigms within the same language.
Ooooh, the memories...
Caml was how I was taught computer science in prépa and first few years of engineering school, a mere 25 years ago.
(Ok, I had done bits of BASIC before, but I had time to recover.)
To be honest, the learning path was
1. Lots of maths. Then add some more.
2. Algos in pseudo code. (In "French", pseudo code, of course, because, why not ?)
3. Caml as "executable pseudo code". With all the warnings and a hints of disgust as the use of mutation and side effect. (And of course ":=" his completely different from "=", what are we, beasts ?)
4. Lots of exams where you have to write properly indented programs on paper on the first try to submit all sorts of recursive trees to all sorts of horrendous manipulations - and you can imagine the grader doing the mother of all code reviews
5. Re do that again in engineering school, because a third of the class had done zero computer science, and the other third had learn in Pascal
6. Then learn C and assembler, and get your mind blown in the exact opposite direction
7. See your teachers reluctantly say that "you should just learn java", because "that's what used in the industry", and "no one will ever get a job writing caml anyway"
...
25 years later : yup, some people managed to get jobs writing a dialect of caml for this small startup in a garage serving cat pictures and racist memes to billions of people
26 years later: "you should just learn to prompt LLMs anyway", because "that's what the industry needs, and no one will get a job programming any more"
Drawing cardioids in maple V while I had darkbasic pro at home and could write my own games and delve into quaternions since 3eme. :x
No wonder I failed this sht, kind of.
Yup, I did not mention the classmates who were already fluent in c++ at 15 and were not that kind of pretending "loops" were mathematical wonder :D
Being a functional programmer in a group of imperative programmers is miserable