OCaml modules and signatures: hide implementation details
8 steps · about 4 h · Intermediate
- Modules · OCaml Documentation (doc, ocaml.org, 25 min)
The official starting point. It shows files as modules, submodules, and abstract and read-only types.
- Files, Modules, and Programs - Real World OCaml (article, Real World OCaml, 45 min)
Builds a multi-file program and shows how a filename.mli file constrains the filename.ml module.
- 5.4. Encapsulation — OCaml Programming: Correct + Efficient + Beautiful (article, Cornell CS 3110 textbook, 30 min)
Uses a stack example to show how abstract types and opacity hide the representation.
- Introduction to the OCaml Module System (article, k-monk.org, 20 min)
Gives a second explanation of signatures as interfaces, with a set example and a first look at functors.
- Modules and Abstraction (article, FP Launchpad OCaml workshop, 25 min)
A workshop page on signature ascription. It shows IntSet.t and int list becoming unrelated types.
- Modules (article, Cornell CS 3110 lecture notes, 30 min)
Covers sharing constraints and the abstract-versus-exposed choice, with comparisons to Java visibility.
- OCaml - The module system (doc, OCaml manual, 35 min)
The reference tutorial chapter. It covers signatures, functors and the with type construct that keeps a type visible when you need it.
- The module language (doc, INRIA, Using OCaml, 30 min)
Explains signature constraints and partially abstract signatures precisely. It makes sense once you have written a few of your own.