Learning ocaml through a f# book?


Hello, i was wondering if it was a good idea to try to learn ocaml through this Book, i heard that f# is pretty similar to ocaml, any thoughts on it ?


I don’t claim to know F#, but no one’s answered yet, and … before I decided to learn OCaml, I looked at F# as well. I would worry that trying to learn OCaml from an F# book would be frustrating.

My understanding is that F# has an indentation-based syntax as well as a more OCaml-like syntax. Also, an F# book would be likely to incorporate .Net library calls into examples. In addition to these libraries being unavailable in OCaml, my guess is that they’d use an objected-oriented style syntax which is uncommon in OCaml. I’m sure there are lots of other little differences between F# and OCaml. F# started from OCaml, but the sense I have is that over time its developers have felt free to add and change things in whatever ways seemed best to them.

So to the extent that parts of a book focus on syntax and concepts that are more or less shared between OCaml and F#, you might learn OCaml with an F# book, but there’s no reason to assume that an author would try to focus on what’s common to the languages.

If you are a moderately experienced programmer, and especially if you have some experience with functional programming, I’d recommend Real World OCaml. Some things are out of date in the published version, but not much. I learned OCaml from it not too long ago, and not much has changed since then. If you like online reading you can read it for free. I like print for learning things like computer languages, and it’s a good thing to financially support the care that the authors and publishers put into the book if possible. (Publishers and editors don’t get enough credit for what they put into creating good books.) There is also a new version of Real World OCaml in the works that’s available online, but I’m not sure how much or what parts have been updated so far.

If you’re closer to being a beginning programmer or don’t feel at all comfortable with functional programming, OCaml from the Very Beginning is supposed to be good.

If you are stuck on a desert island with the F# book and a computer and an OCaml compiler, you could work through it, but otherwise, I suspect that using an F# book for OCaml will be uncomfortable. I don’t know the book you linked to, though, so who knows?


Thank you for your reply, it was insightful and helpful (i actually didn’t thought about the difference of ecosystem between them and the fact that since it’s .Net it would be more OOP style than fp ).
I own Ocaml From The Very Beginning, More Ocaml and Initiation à La Programmation Fonctionnelle En Ocaml (a french book), so i guess i’ll use them alongside the new version of RWO (i should be fine since i have some fp knowledge through scala.)
Excited to get going and learn some ocaml !


You don’t need a F# book.
Just read the manual:
Especially chapters:
Chapter 1 The core language
Chapter 2 The module system
Chapter 4 Labels and variants
Chapter 5 Polymorphism and its limitations
Chapter 6 Advanced examples with classes and modules