Appendices
Syntax cheat sheet, keywords, built-in operator reference, stdlib module map, OCaml version feature timeline (highlights), learning resources and suggested study plan (12 weeks).
Appendices
48.1 Syntax cheat sheet and as assert begin class constraint do done downto effect else end exception external false for fun function functor if in include inherit initializer lazy let match method module mutable new nonrec object of open or private rec sig struct then to true try type val virtual when while with
Reserved infix keywords: asr land lor lsl lsr lxor mod.
48.3 Built-in operator reference Type / meaning pipe / application ref deref / assign mutable field / array assign land lor lxor lnot lsl lsr asr 48.4 Stdlib module map List, Array, Seq, Dynarray
String, Bytes, Buffer, Char, Uchar Int, Int32, Int64, Nativeint, Float, Bool, Unit numbers & primitives Option, Result, Either, Fun
Hashtbl, Map, Set, Stack, Queue, Weak, Ephemeron Printf, Format, Scanf
In_channel, Out_channel, Filename, Sys Lazy, Gc, Obj, Printexc, Marshal, Random, Digest, Lexing, Parsing
Domain, Atomic, Mutex, Condition, Semaphore, Effect Bigarray, Complex, Oo, Type
48.5 OCaml version feature timeline (highlights) ppx, extensible variants, match... exception inline records, [@@unboxed]
Bytes/String separation enforced (immutable strings) Seq, Stdlib module binding operators let*, Option/Result/Fun modules best-fit allocator (default from 4.13) Either module
In_channel/Out_channel, tail-mod-cons multicore runtime, effects, domains
Type module, Mutex.protect, In_channel.input_lines Dynarray, compaction restored, raw identifiers \#foo effect handler syntax in match labeled tuples, immutable arrays (Iarray), further stdlib additions 48.6 Learning resources
Official site & docs: ocaml.org (tutorials, API docs, Playground) Manual: ocaml.org/manual
*Real World OCaml* (2nd ed.) — Minsky, Madhavapeddy (free online: dev.realworldocaml.org)
*OCaml Programming: Correct + Efficient + Beautiful* — Cornell CS3110 (free online + videos) *More OCaml* — John Whitington
*OCaml from the Very Beginning* — John Whitington *Purely Functional Data Structures* — Chris Okasaki (ML/OCaml-style)
*Types and Programming Languages* — Benjamin Pierce (implementations in OCaml)
Exercises: ocaml.org "99 Problems", Exercism OCaml track, Advent of Code in OCaml
Community: discuss.ocaml.org, OCaml Discord, r/ocaml, OCaml Weekly News
Package search: ocaml.org/packages, sherlocode.com (code search), sherlodoc (type search) 48.7 Suggested study plan (12 weeks) Install, REPL, basic types, bindings Functions, currying, recursion
Lists, pattern matching, inference — Part I exercises Records, variants, option/result, higher-order functions
Strings, imperative features, exceptions, data structures, I/O Modules, functors, first-class modules
Dune, testing — Part II exercises, Projects 1–2 Polymorphic variants, GADTs, advanced types & modules
Objects, laziness, monads, Format — Project 3 Effects, multicore, Lwt/Eio — Project 4 or 7
PPX, FFI, GC & performance, compiler — Project 5 Ecosystem, web, packaging — Project 6 + publish a package 🎓 Final Words
You now have a map of the entire OCaml landscape: from let x = 1 to effect handlers, GADTs and multicore parallelism. The fastest way to mastery is to build things, read the compiler's messages carefully, and study well-written libraries (the stdlib source, Base, Eio, Dream). Happy hacking! 🐫
(* Values & functions *)
let x = 5
let f x y = x + y
let f = fun x -> x + 1
let rec loop n = if n > 0 then loop (n - 1)
let f ~label ?(opt = 0) pos = label + opt + pos
(* Types *)
type alias = int * string
type record = { a : int; mutable b : string }
type variant = A | B of int | C of { x : int }
type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree
type _ gadt = I : int -> int gadt
type poly = [ `A | `B of int ]
type ext = ..
type ext += New_case
(* Matching *)
match v with
| A -> ...
| B n when n > 0 -> ...
| B _ | C _ -> ...
| exception Not_found -> ...
(* Modules *)
module M = struct let x = 1 end
module type S = sig val x : int end
module F (X : S) = struct let y = X.x + 1 end
module N = F (M)
let m = (module M : S)
module M2 = (val m : S)
(* Imperative *)
let r = ref 0 ;; r := !r + 1
arr.(i) <- v ;; s.[i] ;; rcd.b <- "x"
for i = 0 to n - 1 do ... done
while cond do ... done
(* Exceptions *)
exception E of string
raise (E "msg")
try expr with E s -> ...
(* Objects *)
let o = object val mutable v = 0 method get = v end
o#get