7.12 Compilation units

unit-interface::= { specification [;;] }
unit-implementation::= [ module-items ]

Compilation units bridge the module system and the separatecompilation system. A compilation unit is composed of two parts: aninterface and an implementation. The interface contains a sequence ofspecifications, just as the inside of a sig … endsignature expression. The implementation contains a sequence ofdefinitions and expressions, just as the inside of astruct … end moduleexpression. A compilation unit also has a name unit-name, derivedfrom the names of the files containing the interface and theimplementation (see chapter 9 for more details). Acompilation unit behaves roughly as the module definition

moduleunit-name:sig unit-interfaceend=struct unit-implementationend

A compilation unit can refer to other compilation units by theirnames, as if they were regular modules. For instance, if U is acompilation unit that defines a type t, other compilation units canrefer to that type under the name U.t; they can also refer to U asa whole structure. Except for names of other compilation units, a unitinterface or unit implementation must not have any other free variables.In other terms, the type-checking and compilation of an interface orimplementation proceeds in the initial environment

name1:sig specification1end … namen:sig specificationnend

where name1 … namen are the names of the othercompilation units available in the search path (seechapter 9 for more details) and specification1specificationn are their respective interfaces.