1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2
"http://www.w3.org/TR/REC-html40/loose.dtd">
6
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7
<META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14">
12
<BODY TEXT=black BGCOLOR=white>
13
<A HREF="manual019.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
14
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
16
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
17
<TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE>
18
<TR><TD><A NAME="htoc88"><B><FONT SIZE=5>6.12</FONT></B></A></TD>
19
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Compilation units</FONT></B></TD>
20
</TR></TABLE></DIV></TD>
23
<DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
24
<TR><TD ALIGN=right NOWRAP>
25
<TT><I><FONT COLOR=maroon>unit-interface</FONT></I></TT></TD>
26
<TD ALIGN=right NOWRAP>::=</TD>
27
<TD ALIGN=left NOWRAP> { <TT><I><FONT COLOR=maroon>specification</FONT></I></TT> [<TT><FONT COLOR=blue>;;</FONT></TT>] }</TD>
29
<TR><TD ALIGN=right NOWRAP>
30
<TT><I><FONT COLOR=maroon>unit-implementation</FONT></I></TT></TD>
31
<TD ALIGN=right NOWRAP>::=</TD>
32
<TD ALIGN=left NOWRAP> { <TT><I><FONT COLOR=maroon>definition</FONT></I></TT> [<TT><FONT COLOR=blue>;;</FONT></TT>] }</TD>
33
</TR></TABLE></DIV><BR>
34
Compilation units bridge the module system and the separate
35
compilation system. A compilation unit is composed of two parts: an
36
interface and an implementation. The interface contains a sequence of
37
specifications, just as the inside of a <TT><FONT COLOR=blue>sig</FONT></TT> ... <TT><FONT COLOR=blue>end</FONT></TT>
38
signature expression. The implementation contains a sequence of
39
definitions, just as the inside of a <TT><FONT COLOR=blue>struct</FONT></TT> ... <TT><FONT COLOR=blue>end</FONT></TT> module
40
expression. A compilation unit also has a name <TT><I><FONT COLOR=maroon>unit-name</FONT></I></TT>, derived
41
from the names of the files containing the interface and the
42
implementation (see chapter <A HREF="manual022.html#c:camlc">8</A> for more details). A
43
compilation unit behaves roughly as the module definition
45
<TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>unit-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> <TT><FONT COLOR=blue>sig</FONT></TT> <TT><I><FONT COLOR=maroon>unit-interface</FONT></I></TT> <TT><FONT COLOR=blue>end</FONT></TT> <TT><FONT COLOR=blue>=</FONT></TT>
46
<TT><FONT COLOR=blue>struct</FONT></TT> <TT><I><FONT COLOR=maroon>unit-implementation</FONT></I></TT> <TT><FONT COLOR=blue>end</FONT></TT>
48
A compilation unit can refer to other compilation units by their
49
names, as if they were regular modules. For instance, if <TT>U</TT> is a
50
compilation unit that defines a type <TT>t</TT>, other compilation units can
51
refer to that type under the name <TT>U.t</TT>; they can also refer to <TT>U</TT> as
52
a whole structure. Except for names of other compilation units, a unit
53
interface or unit implementation must not have any other free variables.
54
In other terms, the type-checking and compilation of an interface or
55
implementation proceeds in the initial environment
57
<TT><I><FONT COLOR=maroon>name</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>:</FONT></TT> <TT><FONT COLOR=blue>sig</FONT></TT> <TT><I><FONT COLOR=maroon>interface</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>end</FONT></TT> ...
58
<TT><I><FONT COLOR=maroon>name</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>:</FONT></TT> <TT><FONT COLOR=blue>sig</FONT></TT> <TT><I><FONT COLOR=maroon>interface</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>end</FONT></TT>
60
where <TT><I><FONT COLOR=maroon>name</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> ... <TT><I><FONT COLOR=maroon>name</FONT></I></TT><SUB><FONT SIZE=2><I>N</I></FONT></SUB> are the names of the other
61
compilation units available in the search path (see
62
chapter <A HREF="manual022.html#c:camlc">8</A> for more details) and <TT><I><FONT COLOR=maroon>interface</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> ...
63
<TT><I><FONT COLOR=maroon>interface</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> are their respective interfaces.
66
<A HREF="manual019.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
67
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>