- The quickstart page to get you up and running as fast as possible.
- OCaml cheat sheet
- Play around with OCaml online using sketch.sh.
- The Beginner’s Guide to OCaml Beginner’s guides
- Learn X in Y minutes where X=OCaml.
- Operator lookup: fun and useful site to look up the function of different OCaml operators.
- Functional Programming with OCaml
- OCaml file types and filename extensions
- The faq: a good place to find answers to questions about OCaml.
- Real World OCaml: A free online book, and a great introduction to OCaml.
- Links to OCaml Q&A around the web.
- Using the OCaml toplevel/REPL
- Article on algebraic data types
- Python to OCaml: a retrospective: Blog entries about rewriting 0Install in OCaml instead of python.
- Functional Alternatives to Inheritance: Beginner-friendly look at alternatives to OOP inheritance.
Setting Up Your Editor for OCaml
Using the OCaml Build Tools
- Quick Start an OCaml project with Dune
- Project showing how to use OPAM with/without dune
- Project showing how to use Dune in different configurations
- OPAM for npm/yarn users
- A sample Dune project
- OPAM 2.0 tips: Local opam installs, pinning, and lock files.
Several guidelines for best practices have been established by the community. See Best Practices.
- Real World OCaml by Y. Minsky, A. Madhavapeddy and J. Hickey (free online):
Functional programming for the masses.
The latest, most up-to-date, and arguably the most readable book on OCaml.
Note that the book uses only Jane Street libraries, but the material can be applied to other libraries.
translation of the
Asynccode examples in the book to use
- RWO-lwt: translation of the
- Cornell OCaml Textbook (free online): Excellent free online book, covering both beginner and advanced topics.
- How to Think Like a (Functional) Programmer by Allen Downey and Nicholas Monje (free online): An introductory programming textbook using OCaml. It is a modified version of Think Python by Allen Downey. This book is intended for newcomers to programming and also those who know some programming but want to learn programming in the function-oriented paradigm, or those who simply want to learn OCaml.
- OCaml from the Very Beginning by J. Whitington: A book for both new programmers and experienced programmers eager to explore functional languages such as OCaml.
Online Exercises for Beginners
- 99 problems: The classic 99 problems, with solutions in OCaml.
- Rosetta Code
- OCaml at Exercism:
Beginner Online Courses
- Introduction to Functional Programming in OCaml
- Cornell University: Data Structures and Functional Programming
- Princeton University: Functional programming in OCaml
- University of Illinois Course on OCaml and Functional Programming
- BigArray: A high-performance array for interacting with non-OCaml programs.
- ocamlunix: Great introduction to systems programming in OCaml
- Higher-Rank Polymorphism in OCaml: How to activate higher-rank polymorphism in OCaml. Old, but still relevant.
- Survey of OCaml programs and their usage of mutable state
The Format Module
The Stdlib has the Format module for pretty printing. It’s a little tricky to get a hang of.
Functional Data Structures
- Purely Functional Data Structures: A classic book focusing on various data structures in the functional programming world. Can be very useful for understanding functional data structures, though OCaml obviously supports imperative data structures as well.
Writing Efficient Code
Intermediate Level Books
- More OCaml: Algorithms, Methods, and Diversions by John Whitington: A meandering tour of functional programming with OCaml, introducing various language features and describing some classic algorithms. The book ends with a large worked example dealing with the production of PDF files. There are questions for each chapter together with worked answers and hints.
- Pearls of Functional Algorithm Design by Richard Bird:
Tackles 30 hard algorithm problems using function programming.
Although it is writtern for Haskell, trying to solve the problems in OCaml also helps develop functional programming.
- Partial solutions in OCaml are available here.
- Scientific Computing in OCaml and Owl (free): Covers OCaml and using the Owl library, which is a heavy-duty library for scientific and numerical computation as well as machine learning.
- Unix System Programming in OCaml by X. Leroy and D. Rémy (free): Introduction to Unix system programming, with an emphasis on communications between processes.
- OCaml for Scientists by Jon Harrop
Modules and Functors
- OCaml polymorphism examples
- OCaml - polymorphic print and type erasure
- Weak Type Variables - when impurity breaks polymorphism
- GADTs in the OCaml manual
- Diff Lists: An application of GADTs to produce heterogenous lists.
- Detecting use-cases for GADTs
- Tradeoffs with GADTs
- Why GADTs matter for performance
- Cambridge University lecture: Programming with GADTs
PPX (PreProcessor eXtensions)
See Metaprogramming for both libraries and articles.
FFI (Foreign Function Interface)
- See FFI.
- Xavier Leroy’s Monadic Programming Lecture Slides (pdf) and code
- Cornell’s CS 3110 Lecture about monads, with code and recitation
- A small monads tutorial from the Monads library
- Discussion on what you can do with Monads and what are Monad Transformers
- Monadic Error Handling
- More Typeclasses in OCaml
- Using, Understanding, and Unraveling the OCaml Language by Didier Remy: Covers both practical and type-theoretical aspects of OCaml.
- Types and Programming Languages by Benjamin C. Pierce: A friendly but serious book on type theory. Much of what’s covered is relevant to OCaml. OCaml implementations of typechecking are presented in the book.
- Advanced Topics in Types and Programming Languages: A more advanced anthology on type theory edited by Benjamin C. Pierce. Includes some articles that are relevant to OCaml.
Category Theory is a branch of abstract mathematics that discusses concepts that tend to pop up as patterns in functional programming.
- First steps with Category Theory and OCaml: Focuses on Monoids and Applicatives.
- Category Theory For Programmers: Not OCaml-specific, but a good book to learn Category Theory from.
- Category Theory For Programmers in Ocaml: An ongoing work to translate CTFP’s code from Haskell to OCaml.