OCaml for the Skeptical
U of C Library DLDC Informal OCaml Class

Parametric, Strongly-Typed, Separately-Compilable Module System

Programming-in-the-large requires a number of features of a programming language; in OCaml, many of these are achieved through the module system.

I will be the first to admit that OCaml's powerful module system (which is very similar to that of Standard ML) is perhaps the most complex part of the language, and that I really don't understand it yet. Fortunately, OCaml makes it very easy to get started. Simply by defining values and functions in a separate file you define a module whose name is the base-part of the filename. You also get a default signature for free, which exposes everything in the module. Just compile this module together with your main program and it works. You can worry about information hiding and type abstraction later.

Parameterized modules may sound like the classes of an object-oriented language, and they are in fact another way OCaml gives you to avoid doing OO. There are advantages to this: calling the functions from a parameterized module is just as efficient as an ordinary function call (which is very efficient in OCaml), without any of the overhead associated with instantiating objects and calling methods. And while the module system has complexities (from the point of view of strong typing), in many ways it's much simpler than an object system -- especially an object system (like OCaml's) that also gives you the advantages of strong typing.

Finally, the OCaml module system is unique (even compared to Standard ML) in that it gives you strong static typing with the efficiency of separate compilation. OCaml can even perform most optimizations (even function inlining) across separately-compiled module boundaries.

What You Need to Know to Use Somebody Else's Modules

Module Signatures for Free