<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <meta name="generator" content="hevea 2.00"> <link rel="stylesheet" type="text/css" href="manual.css"> <title>Compilation units</title> </head> <body> <a href="modules.html"><img src="previous_motif.gif" alt="Previous"></a> <a href="language.html"><img src="contents_motif.gif" alt="Up"></a> <hr> <h2 class="section" id="sec209">6.12  Compilation units</h2> <table class="display dcenter"><tr class="c026"><td class="dcell"><table class="c002 cellpading0"><tr><td class="c025"> <a class="syntax" id="unit-interface"><span class="c014">unit-interface</span></a></td><td class="c022">::=</td><td class="c024"> { <a class="syntax" href="modtypes.html#specification"><span class="c014">specification</span></a>  [<span class="c008">;;</span>] }  </td></tr> <tr><td class="c025"> </td></tr> <tr><td class="c025"> <a class="syntax" id="unit-implementation"><span class="c014">unit-implementation</span></a></td><td class="c022">::=</td><td class="c024"> [ <a class="syntax" href="modules.html#module-items"><span class="c014">module-items</span></a> ] </td></tr> </table></td></tr> </table><p>Compilation units bridge the module system and the separate compilation system. A compilation unit is composed of two parts: an interface and an implementation. The interface contains a sequence of specifications, just as the inside of a <span class="c008">sig</span> … <span class="c008">end</span> signature expression. The implementation contains a sequence of definitions and expressions, just as the inside of a <span class="c008">struct</span> … <span class="c008">end</span> module expression. A compilation unit also has a name <span class="c014">unit-name</span>, derived from the names of the files containing the interface and the implementation (see chapter <a href="comp.html#c%3Acamlc">8</a> for more details). A compilation unit behaves roughly as the module definition </p><div class="center"> <span class="c005"><span class="c007">module</span> <span class="c014">unit-name</span> <span class="c007">:</span> <span class="c007">sig</span></span>  <a class="syntax" href="#unit-interface"><span class="c014">unit-interface</span></a> <span class="c005"><span class="c007">end</span> <span class="c007">=</span> <span class="c007">struct</span></span>  <a class="syntax" href="#unit-implementation"><span class="c014">unit-implementation</span></a> <span class="c008">end</span> </div><p>A compilation unit can refer to other compilation units by their names, as if they were regular modules. For instance, if <span class="c007">U</span> is a compilation unit that defines a type <span class="c007">t</span>, other compilation units can refer to that type under the name <span class="c007">U.t</span>; they can also refer to <span class="c007">U</span> as a whole structure. Except for names of other compilation units, a unit interface or unit implementation must not have any other free variables. In other terms, the type-checking and compilation of an interface or implementation proceeds in the initial environment </p><div class="center"> <span class="c014">name</span><sub>1</sub> <span class="c005"><span class="c007">:</span> <span class="c007">sig</span></span>  <a class="syntax" href="modtypes.html#specification"><span class="c014">specification</span></a><sub>1</sub> <span class="c008">end</span> …  <span class="c014">name</span><sub><span class="c013">n</span></sub> <span class="c005"><span class="c007">:</span> <span class="c007">sig</span></span>  <a class="syntax" href="modtypes.html#specification"><span class="c014">specification</span></a><sub><span class="c013">n</span></sub> <span class="c008">end</span> </div><p> where <span class="c014">name</span><sub>1</sub> …  <span class="c014">name</span><sub><span class="c013">n</span></sub> are the names of the other compilation units available in the search path (see chapter <a href="comp.html#c%3Acamlc">8</a> for more details) and <a class="syntax" href="modtypes.html#specification"><span class="c014">specification</span></a><sub>1</sub> …  <a class="syntax" href="modtypes.html#specification"><span class="c014">specification</span></a><sub><span class="c013">n</span></sub> are their respective interfaces. </p><hr> <a href="modules.html"><img src="previous_motif.gif" alt="Previous"></a> <a href="language.html"><img src="contents_motif.gif" alt="Up"></a> </body> </html>