OCaml tutorials
Your Help is Needed
Many of the tutorials below need updating and tutorials on many new topics are needed. Please contribute by visiting this project's repo on GitHub; you may use the issue tracker there to request or offer new tutorials. Thanks!
Getting Started
Data Structures
Language Features
- Data Types and Matching
- Functional Programming
- If Statements, Loops, and Recursion
- Labels
- Pointers in OCaml
- Null Pointers, Asserts, and Warnings
- Objects
Errors
Interoperability
Build Systems
Advanced Topics
Common Tasks
- Formatting and Wrapping Text
- 99 Problems (solved) in OCaml
- Introduction to Gtk
- Command-Line Arguments
- File manipulation
Acknowledgements
External Links
Learn by Doing
- Try OCaml Online (by OCamlPro) allows you to immediately start learning OCaml in your browser, without installing it. Compiled as a single Javascript page, it gives you the full power of OCaml, even when your are disconnected from the network.
- PLEAC-OCaml provides OCaml solutions to the complete set of problems originally posed in the very successful Perl Cookbook. OCaml is one of only 3 languages for which the full set of solutions has been provided.
- Rosetta is a programming chrestomathy site. It provides solutions to the same task in many languages. Currently there are few tasks with OCaml solutions provided, but perhaps you would like to add new solutions.
Tutorials on OCaml
- The OCaml System (by Inria) is the official user's manual. The first part provides an introduction to the core language, objects and classes, and modules. Previous versions are here.
- How to wrap C functions to OCaml (by Florent Monnier) explains in an understandable way how to write C stubs to call C functions from OCaml and back. It features a lot of examples.
- OCaml for scientific computation (by Thomas Fischbacher), covers a broad sample of OCaml, from the basics to the C API.
WikiBooks on OCaml
- fr.wikibooks.org/wiki/OCaml (in French): Introduction on functional programming using OCaml.
- fr.wikiversity.org/wiki/Premiers_pas_en_OCaml (in French): The basics of the OCaml language.
Tutorials on Tools
There are also tutorials that can be useful to learn how to use popular tools and libraries.
- Camlp4 Tutorial (by Jake Donham), to build syntax extensions for OCaml with Camlp4.
- OCamllex
Tutorial
(by SooHyoung Oh), on how to create lexers using the
ocamllex
tool of the standard distribution. - OCamlyacc
Tutorial
(by SooHyoung Oh), on how to create parsers using the
ocamlyacc
tool of the standard distribution. - LablGTK 2.0 Tutorial (by SooHyoung Oh), on how to create graphical applications with the LablGTK library.
- Camlp5
- A Guide to Extension Points in OCaml (by whitequark), on using PPX, the syntax extensions API that superseded camlp4.
Coming From Another Language
These tutorials help learn OCaml from the perspective of being familiar with another language.
Advanced Tutorials & Articles
- Manual
- Detecting use cases for GADTs in OCaml, (by Mads Hartmann), on using generalized algebraic data types in writing interpreters.
Archived Tutorials
These tutorials are either obsolete, or describe obsolete technologies. They're preserved here just in case they're still useful to someone.
- OCaml and the Web (Outdated, still uses CGI programming.)
- Camlp4 3.10 (Replaced by PPX, see the PPX blog post.)
- Mega Crash course on OCaml ecosystem + code (Too opinionated for a community document.)
- Streams (Use stdlib's Seq introduced in 4.07 or the compatibility opam package.)
- Stream Expressions (Using deprecated camlp4 syntax. See Seq.)