A Crash Course on ML Modules (2015)
This is a good rundown of the basics of ML modules, the syntactic aspects, if you will. But it doesn&#x27;t really give you the important insight:<p><pre><code>  Abstraction. is. powerful.
</code></pre>
if you consider the IntMap module provided in the article, you notice that the type `t` is not defined. It is kept &quot;abstract&quot;. One defining property of ML modules is that you can indeed keep the definition of types hidden and <i>nothing can break abstraction</i>. The rest of the program can only manipulate the type `t` through the functions provided by the module.<p>This allows, in practice, to encode pretty much any property you would like. In the case of maps, you can use BST and never have to worry about users breaking the invariants: the user can&#x27;t even see it&#x27;s a BST! You can provide any form of validation and be sure that the data you manipulate will stay validated (as long as the module is correct, of course).<p>Functors allows you to rely on this by giving you a way to abstract away a whole module. This gives you excellent guarantees: if two modules behaves exactly the same, swapping them is semantic-preserving. Said in another way: if I can prove that sets-as-lists and sets-as-bst are functionally equivalents, then I can swap one for the other, and the rest of the program will behave the same!<p>Refactoring becomes a breeze.
Functors (and modules) makes all the Javaesque reflections and dependency injections completely redundant: modules are (in OCaml) first class objects that you can manipulate and apply as you wish.<p>It also gives you separate compilation! A lot of people say that the OCaml compiler is blazing fast: this is precisely because OCaml&#x27;s module system ensure that each module can be typechecked and compiled incrementally.<p>It pains me that modules get so little appreciation. Many ML programmers get a sort of selective blindness: just like fish in the sea, they don&#x27;t realize the power of what they&#x27;re swimming in. Proper modules with actual abstraction are, in my opinion, the single most essential feature for &quot;large scale&quot; programming.