Introduction to OCaml

OCaml (Objective Caml) is a general-purpose, statically typed, functional-first programming language from the ML family.

1.1 What is OCaml?

OCaml (Objective Caml) is a general-purpose, statically typed, functional-first programming language from the ML family. It combines:

Functional programming — first-class functions, immutability by default, pattern matching.

Imperative programming — mutable state, loops, arrays, exceptions when you need them.

Object-oriented programming — a structural object system with classes and inheritance.

A powerful module system — modules, signatures, functors (functions over modules).

Strong static type inference — you rarely write types, yet everything is checked at compile time.

Fast native code — the native compiler produces efficient machine code; a fast incremental GC.

Multicore (since OCaml 5.0) — shared-memory parallelism with domains and effect handlers.

1.2 History

ML created by Robin Milner (LCF theorem prover) Caml (Categorical Abstract Machine Language) at INRIA

Caml Light (Xavier Leroy, Damien Doligez) Objective Caml 1.0 — adds objects & native compiler Renamed to OCaml

OCaml 4.00 — GADTs, first-class modules improvements opam 1.0 package manager Dune build system becomes standard

OCaml 5.0 — Multicore runtime, effect handlers OCaml 5.1–5.4: performance, restored features, labeled tuples (5.4), etc.

1.3 Who uses OCaml?

Jane Street (trading systems; most of its codebase) Meta (Flow, Infer, Hack type checker originally, Pyre)

Docker (Docker for Mac/Windows networking via MirageOS libraries)

Tezos, Ahrefs, Bloomberg, Citrix (XenServer), Tarides

Compilers & proof assistants: Coq/Rocq, original Rust compiler, Haxe, WebAssembly reference interpreter

1.4 Why learn OCaml?

It teaches you to *model data with types* so illegal states become unrepresentable.

Compiler errors catch bugs early; refactoring is safe.

The module system is one of the most expressive in any mainstream language.

Excellent for compilers, interpreters, static analysis, finance, formal methods.