ML / Standard ML / OCaml — Type Inference Enters the Bloodstream
Origin story
Designers, institution, year
ML (Meta Language) was developed by Robin Milner at the University of Edinburgh starting in 1973, “assisted by research assistants Lockwood Morris and Malcolm Newey, both postdoctoral researchers from Stanford. Michael Gordon, Christopher Wadsworth, and other graduate students joined the research by 1975” (Wikipedia: ML). The name reflects its original role: ML was “conceived to develop proof tactics for the LCF theorem prover and to succeed Stanford LCF,” serving both as “a metalanguage” and “a command and REPL language for the LCF system.”
Standard ML was formally defined during 1986–1989 and published as The Definition of Standard ML in 1990. The HOPL IV paper “The History of Standard ML,” by David MacQueen (University of Chicago), Robert Harper (CMU), and John Reppy (University of Chicago), records that “in the spring of 1983, Robin Milner began an effort to integrate ideas from the Hope language into a new version of ML that would become the Standard ML (SML) Core language. MacQueen proposed a preliminary module system in 1983. A series of design meetings over the next three years refined both the Core language and the module system. Parallel intensive work on a formal semantics led to the publication of the formal definition of the Standard ML language in 1990” (HOPL IV: History of Standard ML).
OCaml — originally Objective Caml — “was first released in 1996” by “Xavier Leroy, Jérôme Vouillon, Damien Doligez, Didier Rémy, Ascánder Suárez, others,” and “is principally managed and maintained by the French Institute for Research in Computer Science and Automation (Inria)” (Wikipedia: OCaml). “Objective Caml was renamed OCaml in 2011.”
The motivating problem
Milner’s Edinburgh LCF theorem prover needed a language for writing proof tactics — programs that manipulate proof objects — that would be safe (a bogus tactic must not produce a bogus theorem), expressive (higher-order functions were essential), and interactive (a REPL for exploratory proof). Milner’s insight was to use the type system as the safety mechanism: theorem values would inhabit an abstract type whose constructors were only the sound inference rules. This forced the invention of what became Hindley–Milner type inference — a way to give programs principal types without programmer annotations, which Milner formalized in his 1978 paper A theory of type polymorphism in programming (Wikipedia: ML).
For OCaml, the lineage runs Caml → Caml Light → Caml Special Light → Objective Caml:
- Caml was designed at INRIA’s Formel team headed by Gérard Huet; first implementation 1987–1992, initially by Ascánder Suárez, then Pierre Weis and Michel Mauny after Suárez left in 1988 (Wikipedia: OCaml).
- Caml Light (1990–1991): Xavier Leroy’s bytecode implementation in C with Damien Doligez’s sequential garbage collector, small enough for desktop machines.
- Caml Special Light (1995): Leroy added an optimizing native-code compiler achieving performance “comparable with mainstream languages such as C++” and designed a high-level module system inspired by Standard ML’s.
- Objective Caml (1996): Didier Rémy and Jérôme Vouillon added a statically-typed object system.
Initial reception
ML the language was, for a decade, primarily an academic tool inside LCF and its descendants. Standard ML’s 1990 formal definition made it the first widely-taught language with a full mathematical semantics. OCaml gained early industrial traction in France (INRIA), then in a handful of firms — most famously Jane Street Capital, which “adopted OCaml as its preferred language in its early days [and] continued to use OCaml as of 2023” (Wikipedia: OCaml).
Design philosophy
Core principles
- Types are inferred, not annotated. Programmers write ordinary functional code; the compiler infers the most general type.
- Algebraic data types with pattern matching make case analysis exhaustive and total.
- Functions are first-class with full closures.
- Separation of pure and impure (partial, in ML — SML has references and mutation; OCaml likewise).
- A powerful module system with signatures, structures, and functors (parametric modules) — Standard ML and OCaml both.
What ML rejected
Dynamic typing, subclass-based inheritance (ML has no class inheritance; OCaml added structural subtyping only), unsafe casts, and implicit conversion. Standard ML’s 1997 revision even rejected some pre-existing conveniences: the revision “notably revised the value restriction rule controlling the interaction of polymorphism and mutable data” and made “signatures more expressive… provided for opaque signature matching” (HOPL IV).
Cultural values
Rigor, minimalism, mathematical precision. The Definition of Standard ML is famous for being a complete formal semantics — natural-deduction rules for every construct — that “stabilized and constrained the evolution of Standard ML” and “enabled multiple largely compatible implementations of the language” (HOPL IV).
Language features
Syntax
ML uses let ... = ..., let rec, fun, match ... with, pipe operators, and Haskell-like currying. OCaml’s syntax is close enough to SML’s that literate readers can move between the two, with mild differences (SML uses fn for lambdas, OCaml uses fun; SML uses datatype, OCaml uses type).
Type system
- Hindley–Milner polymorphism: principal type inference, let-polymorphism, no annotations required.
- Algebraic data types (SML calls them
datatype, OCamltype) — sum-of-product with pattern matching. - Records with named fields.
- Tuples and references (mutable cells).
- OCaml adds: structural subtyping for objects, polymorphic variants, GADTs (added in OCaml 4.0, 2012), first-class modules (4.0), and starting with 4.02, extensible variants.
- Effect handlers via delimited continuations landed in OCaml 5.0 (2022) (Wikipedia: OCaml).
Module system
SML and OCaml both provide structures (implementations), signatures (interfaces), and functors (functions from modules to modules). This module system, standardized in SML’s 1990 Definition and imported into OCaml, remains one of the most expressive in production languages. The 1997 revision “simplified and enriched the module system… made signatures more expressive… provided for opaque signature matching” (HOPL IV).
Memory model and GC
Both SML and OCaml are garbage-collected. Damien Doligez’s incremental generational GC in OCaml is famous for very low pause times. OCaml 5.0 (2022) “completely rewrote the language runtime, removed the global garbage-collector lock, added effect handlers via delimited continuations, enabled support for shared-memory parallelism, enabled support for color-blind concurrency” (Wikipedia: OCaml).
Concurrency
- SML never standardized concurrency; Concurrent ML (CML) by John Reppy provides synchronous message passing.
- OCaml shipped only cooperative concurrency and green threads for two decades. OCaml 5.0 (2022) finally added shared-memory parallelism by removing the runtime lock, and provides algebraic effect handlers used by libraries like Eio and Domainslib for structured concurrency (Wikipedia: OCaml).
Error handling
Both use exceptions with raise/handle (SML) or raise/try ... with (OCaml). Idiomatic modern OCaml also uses result types (Ok/Error) inspired by Haskell/Rust for expected errors.
Metaprogramming
- SML has essentially no macros; the module system does much of the work.
- OCaml has PPX (preprocessor extension) rewriters — AST-level syntactic extensions applied by
ppxlib— plusCamlp5historically.[@@deriving]extensions (viappx_deriving) generate boilerplate at compile time.
Implementation
Reference implementations
- Standard ML of New Jersey (SML/NJ) — the reference SML implementation from Bell Labs, native-code, with continuation-passing-style compilation.
- MLton — a whole-program optimizing SML compiler producing very fast native code; famous for aggressive monomorphization.
- Moscow ML — a lightweight portable SML implementation.
- Poly/ML — SML for the Isabelle theorem prover.
- OCaml — the sole reference implementation, developed at INRIA (Cristal team until 2005, Gallium team after 2005, Cambium team after 2019). The 2023 count was “23 core developers of the compiler distribution from a variety of organizations… 41 developers for the broader OCaml tooling and packaging ecosystem.” “In 2023, the OCaml compiler received ACM SIGPLAN’s Programming Languages Software Award” (Wikipedia: OCaml).
Lexer, parser, IR, backend
The OCaml compiler is a classical multi-pass affair: hand-written lexer + LR(1) parser (Menhir replaces ocamlyacc in modern builds); typed AST; lambda IR; two backend paths — a bytecode compiler (ocamlc) targeting a portable VM, and a native compiler (ocamlopt) targeting x86-64, ARM64, RISC-V and other architectures. ocamlopt’s IR is Lambda → Clambda → Cmm → native.
Runtime and GC
Sequential incremental generational GC (Doligez), from Caml Light through OCaml 4.x. OCaml 5.0 rewrote the runtime for a parallel GC (Wikipedia: OCaml).
Bootstrapping
The OCaml compiler is written in OCaml and bootstraps through prior releases.
Alternative implementations
- js_of_ocaml — compiles OCaml bytecode to JavaScript.
- BuckleScript (Bloomberg, later ReScript) — OCaml compiler backend targeting readable JavaScript; ReScript now has its own syntax layer but retains OCaml semantics (Wikipedia: OCaml).
- OxCaml — a Jane Street fork announced June 2025 for advanced type-system experiments (unboxed types, modes, kinds) (Wikipedia: OCaml).
Ecosystem
Package manager
opam is OCaml’s package manager and version-solver, extremely capable and central to the modern ecosystem. Also dune as the build system (superseded jbuilder, ocamlbuild, oasis).
Standard library
SML has the Basis Library (finalized in the 1990s as part of the SML ‘97 work). OCaml’s standard library is minimal by modern standards; the community has multiple alternative libraries (Jane Street’s Base and Core, Containers, Batteries).
Tooling
Excellent: Merlin and ocaml-lsp-server provide LSP; ocamlformat formats; odoc generates documentation; utop is an enhanced REPL; ppxlib is the syntax-extension framework.
Community and governance
OCaml is stewarded by INRIA with input from a Software Foundation (OCaml Software Foundation) established to support the community. SML has no active language committee; Standard ML’s Definition is essentially frozen.
Adoption
Where it’s used
OCaml:
- Jane Street Capital — one of the largest OCaml deployments in the world; the firm has consistently invested in the compiler and open-sourced Core, Async, and now OxCaml (Wikipedia: OCaml).
- Facebook/Meta — “Flow, Hack, Infer, Pfff, ReasonML” were all developed in OCaml.
- Bloomberg — BuckleScript / ReScript.
- Citrix — XenServer (Citrix Hypervisor).
- Docker — “uses OCaml in its desktop editions on macOS and Windows.”
- Tezos, MirageOS, and many verification tools.
SML: HOL4 and Isabelle/HOL theorem provers rely on it; academic use in teaching PL semantics.
Where it dominates
Financial trading (Jane Street), static analysis (Infer), high-assurance tools (theorem provers), unikernels (MirageOS), and small pockets of language tooling.
Where it failed to penetrate
Mainstream application development. Despite ML’s evident technical superiority in the 1990s, Java captured the enterprise object-oriented market, and Python captured scientific and scripting work. OCaml’s small standard library, French-INRIA origin, and until-recently-single-core runtime kept it a niche.
Current momentum (2026)
OCaml 5’s parallel runtime (2022) and continued investment by Jane Street and Tarides have revitalized momentum; the 2023 SIGPLAN Software Award is a marker. The ecosystem is small but active, with regular releases and steady industrial adoption.
Criticism and open problems
- Small standard library relative to competitors.
- Single-core for two decades; OCaml 5.0 finally fixed this in 2022 but ecosystem catch-up is ongoing.
- Tooling story improved dramatically with LSP/dune but still trails Java/Rust in some areas.
- Ecosystem fragmentation between INRIA-standard and Jane Street’s Core/Base can be confusing for newcomers.
- Syntax quirks (mandatory
;;in REPL, precedence of|inmatch, etc.) are frequent complaints. - SML has stagnated since 1997; no new standardization work.
Influence on other languages
Wikipedia notes that “in the early 2000s, elements from OCaml were adopted by many languages, notably F# and Scala” (Wikipedia: OCaml). Direct descendants and influences:
- F# — Don Syme at Microsoft Research; nearly a .NET port of OCaml.
- Haskell — shared HM type inference and ADTs; different in laziness and purity.
- Scala — Odersky drew on ML’s ADTs, pattern matching, and higher-order functions.
- Rust — algebraic data types, pattern matching,
Option/Result,matchexhaustiveness, immutability by default — directly from ML. - Swift — enums with associated values (ADTs),
Optional, pattern matching. - Elm and PureScript — ML-family languages targeting JavaScript.
- TypeScript — discriminated unions, exhaustiveness checking of
switch. - Kotlin, Scala 3, Java 17+ pattern matching — all trace back to ML’s sum-of-product ADTs.
Key sources
- Robin Milner, Mads Tofte, Robert Harper, David MacQueen, The Definition of Standard ML (Revised), MIT Press, 1997.
- Robin Milner, “A theory of type polymorphism in programming,” Journal of Computer and System Sciences, 1978 — the HM paper.
- David MacQueen, Robert Harper, John Reppy, “The History of Standard ML”, HOPL IV, 2020 (published 2021), doi:10.1145/3386336.
- Xavier Leroy et al., The OCaml System — Documentation and User’s Manual, INRIA (current release).
- Wikipedia: ML and Wikipedia: OCaml.
- Jason Hickey, Introduction to Objective Caml.
- Yaron Minsky, Anil Madhavapeddy, Jason Hickey, Real World OCaml (O’Reilly).