Jump to ratings and reviews
Rate this book

Real World OCaml: Functional programming for the masses

Rate this book
This fast-moving tutorial introduces you to OCaml, an industrial-strength programming language designed for expressiveness, safety, and speed. Through the book’s many examples, you’ll quickly learn how OCaml stands out as a tool for writing fast, succinct, and readable systems code.

Real World OCaml takes you through the concepts of the language at a brisk pace, and then helps you explore the tools and techniques that make OCaml an effective and practical tool. In the book’s third section, you’ll delve deep into the details of the compiler toolchain and OCaml’s simple and efficient runtime system.


Learn the foundations of the language, such as higher-order functions, algebraic data types, and modules
Explore advanced features such as functors, first-class modules, and objects
Leverage Core, a comprehensive general-purpose standard library for OCaml
Design effective and reusable libraries, making the most of OCaml’s approach to abstraction and modularity
Tackle practical programming problems from command-line parsing to asynchronous network programming
Examine profiling and interactive debugging techniques with tools such as GNU gdb

510 pages, Paperback

First published January 1, 2013

Loading interface...
Loading interface...

About the author

Yaron Minsky

3 books

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
49 (42%)
4 stars
46 (40%)
3 stars
16 (14%)
2 stars
3 (2%)
1 star
0 (0%)
Displaying 1 - 10 of 10 reviews
Profile Image for Josh.
250 reviews27 followers
December 7, 2015
Does what it says on the tin — this book focuses on teaching ocaml with lots of code examples that strive to be close to things you'd really do. The first major section discusses the language itself, which is quite thorough, and the second section is about practical patterns, like concurrency and when to use certain data types. The practicality extends to its use of Core, a replacement standard library, instead of trying to teach the language without any dependencies — that's not how you're going to use it.

Overall, very few issues with code examples or things that I thought were explained badly or glossed over. Recommended. Plus, you can read it online for free. I did.
Profile Image for Stefan Kanev.
125 reviews205 followers
September 3, 2019
This book is a gem.

OCaml is a great language – I regret not learning it when I had more free time on my hands. It feels very reminiscent of Haskell, with two major differences – it's strict and it allows side effects. Those make reasoning about behaviour easier and removes the need for all that monad transformer nonsense. It's also very feature rich and it even has objects (although they are not as prominent as you would except, given that the O in OCaml stands for "Objective"). It seem to be the functional language to choose if you're doing something practical. For example, Facebook is using it for Hack, Flow and ReasonML.

There is a trading firm, Jane Street Capital, that uses OCaml for all their stuff. They've completely rewritten the standard library and have a set of replacement libraries (Base, Core_kernel and Core). The book introduces you to OCaml through those libraries, which is not surprising, as it shares an author with them (Yaron Minsky). I don't know whether it's industry standard, but it's pretty good and worth learning.

The book starts with an introduction to the language, slowly accellerates with some examples of dealing with hashes, command line tools and JSON, and goes completely bonkers into parsing, lexing, asynchronous programming, FFI, the memory layout and the garbage collector, and finally the compiler frontend and backend. While the first chapters are quite casual, the final ones can be quite the challenge. Unless you enjoy PLT, in which case they are quite the treat.

On the down side, it did not feel like it covered all corners of the language. There are bits in the OCaml manual that were not explored in the book, and I was left with the impression that the language is deeper than Real World OCaml made me think. Still, maybe this is for the better – I got much more excited about seeing some applications than I would have if it covered every nook and cranny first.

If you're into functional programming and you don't know OCaml yet, you should definitely learn it. This is the book to start with.
46 reviews
November 1, 2020
(V2 prerelease)

Incredible introduction to most of the most important aspects of OCaml. Language features are generally motivated by examples and shown in context of complete programs. The book includes lots of different domain-specific examples and use of external libraries.

Be aware that most (all?) of the examples use/depend on the Base/Core libraries, which uses its own set of idioms that differ from the built in standard library. For the most part, this is actually a good thing, but this can make some of the examples more difficult to adapt to different frameworks/existing code.

Main complaints: not enough depth of coverage some of the more advanced language extensions, such as recursive modules, GADTs, the new monadic syntax, advanced build configurations with Dune (for example, when targeting both native and js_of_ocaml), or detailed C interop. Instead, the reader is referred to the OCaml manual, which is decent but does not contain nearly as much context as most of the worked problems in this book. In my case, this was fine, since my desire to use these features actually arose from my own problems (for example, using PPX derivers on recursive structures basically required recursive modules).

In all, this book is an great starting point for learning how to use OCaml for real projects. However, you will need to consult other resources such as the OCaml manual, Dune documentation, and the (excellent) OCaml community forums for more advanced projects.

Note: I skimmed the chapter on parsing. Additionally, at the time I read this book, the chapters on testing and PPX were incomplete. It’s possible that the final release will include more information about extensions.
Profile Image for Piotr Kalinowski.
51 reviews18 followers
May 26, 2019
This is a very thorough and practical introduction to the language. It goes pretty much through all the features of the language itself — from core language through first class modules, functors to the object system. The only thing missing at this point is authoring your own syntax extensions, but you have to draw the line somewhere, and I think that's a good place to stop.

The book does not use the small standard library delivered with the compiler, and for good reason. It focuses on one of the most popular replacement library that is quite modern and proven in the industry, even if not necessarily my first choice due to what I am currently using OCaml for. The choice will only matter significantly with respect to few chapters from the practical part — if you choose different libraries, you will probably not be using their sexp serialisation or the async library.

I especially liked inclusion of chapters describing in more detail how compiler and garbage collection work. You might never need to toy with these, but personally I believe in having some overview of how your source code turns into machine instructions and what to expect from runtime performance and memory usage.
Profile Image for RecursiveHaiku.
69 reviews
July 2, 2020
I read the updated v2

This is a great book to learn the basics of OCaml.
It explains all of the basic concepts and goes beyond them.
It benefits hugely from the fact that it is co-written by people who are actively using and driving OCaml forward.

It also is a decent reference book for features of OCaml since the online documentation can be VERY BAD for beginners.
Profile Image for Ondrej Sykora.
Author 3 books12 followers
March 14, 2014
I might be a bit harsh, but based on all the positive reviews, I've expected much more of the book.

What you get is an easy introduction to the OCaml world that touches most of the aspects of software development in OCaml. However, when they approach a more complex topic, the authors just say "there is some magic going on", and they abandon it. For example the SExp library. I'd love to learn how it is implemented and how the compiler extension is developed, but the book does not touch any of that, but no, "here's some magic, let's move on".

It would also help readability, if the code examples were syntax-highlighted (and if they used proper file names), but that's nothing serious.

If you're looking for a mostly complete introduction to the language, go ahead and read it. However, if you already know OCaml basics and you would like to understand the principles in detail, you should look for other sources.
Profile Image for Alvaro Tejada Galindo.
175 reviews5 followers
April 4, 2017
This book, just like all the "Real World" series gives you a deep introduction into the language and allow you to start coding pretty fast...of course...if you have used any Functional programming language before...that really helps and OCaml has of course some aspects that makes it not so easy to learn...

The more you read this book, the more you're going to like OCaml...it's a really nice language -:)

The book covers the basics like Lists and Patterns, Records, Variants and Error-Handling. But of course it goes beyond with Functors, Objects and Command-Line Parsing...not letting important concepts like JSON handling Concurrent Programming aside. So...it's a pretty complete reference to start out.

By the way...the book is 509 pages...so it's pretty long...but full of examples and demonstrations...
Profile Image for Kenneth Miller.
34 reviews2 followers
September 9, 2015
It was good. My first book on OCaml, it was pragmatic enough to teach you the common gotchas, while also being straightforward and sufficiently organized that it can be used as a reference.
Profile Image for Hongchang.
6 reviews
May 1, 2017
As a professional OCaml developer I can say that this is probably the best English OCaml book out there. It covers all the import aspects of this wonderful yet idiosyncratic programming language. However I do wish the that it could focus more on the OCaml language and standard library itself and less on the Jane Street Core Library. Don't get me wrong, Core is a high quality library but it's just that - a library. I don't think it is essential for learning the OCaml itself.
Displaying 1 - 10 of 10 reviews

Can't find what you're looking for?

Get help and learn more about the design.