Learn Programming with OCaml (new book)

I also completly lost my motivation to make some “learn ocaml with cleopatra” tutorials, because people really have a bad and hurtful humor with it.

when i made “learn ocaml with the predator”, they found it funny to block me with three cars on the way when I tried to go watch the movie.

if I make “learn ocaml with major hamster” for the children they will probably find it funny to break one of my arms, or three fingers.

Thanks for that work.

Coming back to OCaml, a few years ago, before RWO was released (and sadly was not relying on stdlib, adding a hurdle), there were already many books and I wondered if your book was the best for [re]learning OCaml.

As there are many OCaml books, can you pls. tell us (especially tell beginners) what is this book for and what it is NOT for (its positioning)?

NB: surprisingly, this updated book may be also a good introduction to… dune!…

Hello @Luc_ML,

Great to hear that you’re not giving up on OCaml. My two cents: choosing the right book to learn OCaml really depends on your goals and background. Since you’re experienced in programming but new to OCaml, here’s a tailored breakdown of your options:

  1. For learning by example: The book discussed in this thread by @backtracking (I think author of the widely used ocaml-graph library) is a solid choice. It emphasizes practical examples along with insights into data structures, making it well suited for developers who want to jump in and start coding right away.

  2. For a deeper dive into OCaml:

  • Real World OCaml (RWO) is a classic. I agree that it uses Core instead of the standard library (there are GitHub repositories that re-implement the examples using the stdlib). As you said this can be a hurdle at first, but the book covers a wide range of OCaml topics and offers many valuable insights and best practices.
  • OCaml Programming: Correct + Efficient + Beautiful is another strong option, with a balanced mix of theory and practice. In my view, this book focuses on teaching both OCaml and functional programming concepts. You’ll likely enjoy it if you like learning underlying ideas, not just working through examples.
  1. For absolute beginners (to programming): If someone is completely new to programming, the two books above might not be the best starting point. In that case, I’d recommend beginning with more beginner-friendly tutorials.

Additional OCaml resources:

  • ocaml.org/books: A list of books covering various levels and also specific topics.
  • OCamlverse: Useful, though not updated very frequently.
  • OCaml Videos: Mostly high-level, but some are fun and informative to watch.

Here are some resources to help you with Dune, but to be honest, I haven’t found a single “perfect” tutorial or learning path, but these are still quite helpful:

If you prefer video content, you might also like:


Some interesting links to have in mind:

Hoping this can be useful. All the best.

1 Like

As lately indicated in another discussion, I’m correctly experienced in OCaml and other languages.
I’m just somehow unexperienced in, from scratch and quickly, setting up a modern, reliable and powerful full featured Ocaml IDE, especially for Windows (Win, because some people of my team only want to use Win, and I would also like to have it on my Win laptop without a Docker container or a VM).

Anyway, thanks for your pointers that may interest some people, and feed a discussion.

However, your efforts also highlights that it’s hard to have a clear learning path.

I personaly started to [re]learn OCaml with studying all details in refman in pdf (ctrl-f and links), and learned a lot with it, also reading the stdlib (what is under the hood), and using intensively the toplevel to evaluate every expression. I only had to understand ocaml and its tools (ocamlbuild, findlib, topfind, ocamlmktop,… and bash stuff for that). Maybe it’s the hard way but I can remember most details of the foundations.

I’m supposed to help folks in a team to quickly learn OCaml, which also means make them setup a professional OCaml IDE and keep it operational.

Any good book is welcome.
btw, OCaml from the Very Beginning (free) and More OCaml: Algorithms, Methods, and Diversions written by @JohnWhitington where very helpful for me.

Side comment to “Learn programming with OCaml” :
Again, on Ocaml landing pages, is it a good idea to expose a beginner to weird and useless expressions such as opam exec -- dune init project hello_world while dune init project hello_world is enough, after opam is correctly configured and its basics understood?
Or dune exec -- ./helloer.exe instead of usual ./helloer.exeor dune-style dune exec helloer

Abstracting/replacing the OCaml foundational commands for producing the necessary “executable stuff”(.cmi, .cmo, .cmx, .o, .bc, .exe, etc.) should stay as simple as possible, and always… pleasant.
https://ocaml.org/docs/your-first-program
https://ocaml.org/docs/bootstrapping-a-dune-project

1 Like

No, this is not what I meant, I wanted just to give you several options. I just tried to say that there is not perfect tutorial for everyone, so try to find your way.

You already opened a discussion about opam exec -- dune in other thread and you had a lot of replies, so I don’t see the need of mentioning here again.

Please see my comment here about dune stanzas. You can use dune init proj to explore the dune files. Sometimes the trees doesn’t allow us to see the forest. Be patient.

1 Like

I precisely recommend we have much more consideration towards beginners, new comers and come backers.
Assuming Ocaml is a good PL (and it is !), I believe these people should have immediate access to:

  • “super excellent” tools for programming : and IDE with no headache and a minimal documentation because of… good tools.
  • good and pertinent resources for learning : @backtracking’s book is great ; but other resources are needed. And training requires good tools to keep learning at good pace…
  • good resources for discussing and get help : discuss.ocaml.org is great for that, even if non experts are sometimes giving their opinion without a deep understanding (!)
1 Like

Well @Luc_ML,

I was trying to be kind and measured, but I disagree with some of your comments, especially the one where you spoke about the Dune developers,

and what the hell could happen in his life so the chief dune designer let make that choice.

Speaking about the work done by other developers without even considering that they may have reasons for their decisions is not nice. The same applies to your comments about tutorials, it is not what you said, but how you said it. I was trying to do the opposite, to say that I understand your points and that your feedback is welcome, but you did not realize that this was also meant as a mirror of how we should communicate about other people’s work.

There has been a lot of work and input from many people on the OCaml platform tools and tutorials. This deserves respect. There have been huge improvements and efforts in recent years that need to be recognized and valued. Obviously, there are still many things to improve, but sentences like the one quoted above are honestly not helping. Other lines like:

good resources for discussing and get help : discuss.ocaml.org is great for that, even if non experts are sometimes giving their opinion without a deep understanding (!)

Are also not nice, all people here is trying to help, and many of them replied you with the aim of help you (with different degrees of knowledge of course). So please take that in consideration.

My point is very different from yours. I do think that, for beginners, there is enough material, tutorials, and tools. However, when you cross the line to mid-level, there is a gap. There is material for experts and for beginners, but the transition is not always easy. This is where I see value in the book mentioned in this thread.

I encourage you to try to understand other people’s positions and opinions, and to share your own opinion in a balanced way, as no one has the final answer to anything.

4 Likes

Hi, It seems your are mixing up discussions in a confusing manner (putting here an extract of a sarcastic comment from an other discussion, out of its context).

And it seems that you don’t want to hear the sometime ugly experience I had or people I work with had with Ocaml tools (including dune), with documentation (especially with landing pages), And recommendations based on global experience

Pls.don’t try to teach me how I should communicate. I’m interested in facts, truth. Hence often the hard way. In order to build on that and go towards better tools and documentation for OCaml. You may prefer nice stories for children. I don’t. What about a PM to discuss personal stuff?

Well @Luc_ML,

  • I sent you a PM before, but you mostly ignored it.
  • You brought this discussion here from another thread, so I had to reply here, not my choice.
  • As I said, it is not what you say, but how you say it. And yes, the how is very important.

And it seems that you don’t want to hear the sometime ugly experience I had…

  • False. I replied about 6 o 7 times to your questions on different topics. Trying to help you and understand your points, obviously. This is not someone who doesn’t want to hear about something but genuinely try to provide feedback; I replied thoughtfully and recognized your points when I agreed. Just above I said to you “Obviously, there are still many things to improve”.

Pls.don’t try to teach me how I should communicate. I’m interested in facts, truth. Hence often the hard way.

  • If you are interested in facts and truth, the first point is to understand the perspective and vision of others, unless you think you already know the truth.
  • “The hard way” usually does not work well.
  • Communication is not only about speaking but also about listening, and listening requires balancing other views.

You may prefer nice stories for children.

  • Do you really think that is a way to reply to others, who provided you feedback, info, links…? and those that also agreed that improvements are needed…

Of course PM is better, and I tried before.

1 Like

Thanks for confirming it’s useless to discuss together that way, especially in public space, because [it appears to me that] you prefer to focus on how more than on what.

I personaly don’t appreciate « stories for children » when dealing with hard stuff! such as compiler and tools! Pls. don’t forget my motivation regarding OCaml, its tools and its documentation (this discussion is an announce for a book, and documentation is one key).

Pls don’t take personally all I can write… I’ll make an effort with PM so can appreciate my friendship.

…PM is certainly better…

Again, I wrote you a PM that you ignored. I stop here any communication.

My answer to your PM didn’t satisfy you. And you may took that personally.

I agree to stop this communication, and I apologize for all the « noise » we made.

Wondering if this is still checked?

I submitted a fix for Windows regarding a build command quite some time ago, was quite frustrating for me before I figured that out and a footnote would help others as well.