OCaml modules and signatures: hide implementation details

8 steps · about 4 h · Intermediate

  1. Modules · OCaml Documentation (doc, ocaml.org, 25 min)

    The official starting point. It shows files as modules, submodules, and abstract and read-only types.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. Modules (article, Cornell CS 3110 lecture notes, 30 min)

    Covers sharing constraints and the abstract-versus-exposed choice, with comparisons to Java visibility.

  7. 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.

  8. 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.