- Courses
- 💻Programming Languages
- 🐫OCaml (WIP)
- Modules, Structure & Tooling
On this page
OCaml Modules, Project Structure, and Tooling
Every OCaml file written so far has lived on its own, but real software is built from many files working together, with clear boundaries between what's exposed to the rest of a program and what stays private. This collection covers exactly that transition: how files become modules, how .mli signatures control what's visible from outside a module, how Dune organizes libraries, executables, and tests as a codebase grows, how third-party packages get discovered and installed through opam, and how a project gets tested and documented to a standard fit for publishing.
Structure of this Module
This module is organized into the following lessons or articles. Feel free to start from wherever you like.
📄️Files as Modules
How every OCaml file becomes a module automatically, how cross-file references work, and how Dune organizes multi-file projects.
📄️Module Signatures
How .mli files control what a module exposes, enforce invariants through abstract types, and let implementations change safely.
📄️Nested Modules
How to define modules inside other modules in OCaml, give a submodule its own signature, and when nesting is the right tool.
📄️Module Aliasing
How module aliasing works in OCaml, why it costs nothing at runtime, and how it differs from open and include.
📄️Dune Deep Dive
How Dune's library, executable, and test stanzas differ, how dependencies are declared, and how the three work together.
📄️OPAM Package Discovery & Installation
How to search for OCaml packages with opam, install them reproducibly, and wire them into a Dune project.
📄️Unit Testing
How to write and run OCaml unit tests with Alcotest's testable system, and a brief look at the OUnit2 alternative.
📄️Documentation Generation
How to write odoc doc comments, generate HTML documentation through Dune, and structure a package's documentation pages.
📄️Guided Exercise: Build a Mini Library
A guided project building a functional queue library with a hidden implementation, Dune packaging, Alcotest suite, and odoc docs.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Exercise: Build Your Own List Module
Next
Files as Modules
- Structure of this Module