1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset= ISO-8859-1">
<TITLE>
Compilation units
</TITLE>
</HEAD>
<BODY >
<A HREF="manual017.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual006.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<HR>
<H2>5.12 Compilation units</H2>
<DIV ALIGN=center>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>unit-interface</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP> { <TT><I><FONT COLOR=maroon>specification</FONT></I></TT> [<TT><FONT COLOR=blue>;;</FONT></TT>] }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>unit-implementation</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP> { <TT><I><FONT COLOR=maroon>definition</FONT></I></TT> [<TT><FONT COLOR=blue>;;</FONT></TT>] }</TD>
</TR></TABLE></DIV><BR>
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 <TT><FONT COLOR=blue>sig</FONT></TT> ... <TT><FONT COLOR=blue>end</FONT></TT>
signature expression. The implementation contains a sequence of
definitions, just as the inside of a <TT><FONT COLOR=blue>struct</FONT></TT> ... <TT><FONT COLOR=blue>end</FONT></TT> module
expression. A compilation unit also has a name <TT><I><FONT COLOR=maroon>unit-name</FONT></I></TT>, derived
from the names of the files containing the interface and the
implementation (see chapter <A HREF="manual020.html#c:camlc">7</A> for more details). A
compilation unit behaves roughly as the module definition
<DIV ALIGN=center>
<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>
<TT><FONT COLOR=blue>struct</FONT></TT> <TT><I><FONT COLOR=maroon>unit-implementation</FONT></I></TT> <TT><FONT COLOR=blue>end</FONT></TT>
</DIV><BR>
A compilation unit can refer to other compilation units by their
names, as if they were regular modules. For instance, if <TT>U</TT> is a
compilation unit that defines a type <TT>t</TT>, other compilation units can
refer to that type under the name <TT>U.t</TT>; they can also refer to <TT>U</TT> 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
<DIV ALIGN=center>
<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> ...
<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>
</DIV>
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
compilation units available in the search path (see
chapter <A HREF="manual020.html#c:camlc">7</A> for more details) and <TT><I><FONT COLOR=maroon>interface</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> ...
<TT><I><FONT COLOR=maroon>interface</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> are their respective interfaces.
<HR>
<A HREF="manual017.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual006.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
</BODY>
</HTML>
|