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 64 65 66 67 68 69 70 71 72 73
|
<!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">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="manual.css">
<TITLE>
Compilation units
</TITLE>
</HEAD>
<BODY >
<A HREF="manual019.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<HR>
<H2 CLASS="section"><A NAME="htoc90">6.12</A> Compilation units</H2>
<BR>
<BR>
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<A NAME="unit-interface"></A>
<FONT COLOR=maroon><I><TT>unit-interface</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP> { <FONT COLOR=maroon><I><a href="manual018.html#specification"><font color=maroon><TT>specification</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>;;</TT></FONT>] }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="unit-implementation"></A>
<FONT COLOR=maroon><I><TT>unit-implementation</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP> { <FONT COLOR=maroon><I><a href="manual019.html#definition"><font color=maroon><TT>definition</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>;;</TT></FONT>] }</TD>
</TR></TABLE></DIV><BR>
<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 <FONT COLOR=blue><TT>sig</TT></FONT> … <FONT COLOR=blue><TT>end</TT></FONT>
signature expression. The implementation contains a sequence of
definitions, just as the inside of a <FONT COLOR=blue><TT>struct</TT></FONT> … <FONT COLOR=blue><TT>end</TT></FONT> module
expression. A compilation unit also has a name <FONT COLOR=maroon><I><TT>unit-name</TT></I></FONT>, derived
from the names of the files containing the interface and the
implementation (see chapter <A HREF="manual022.html#c:camlc">8</A> for more details). A
compilation unit behaves roughly as the module definition
<DIV CLASS="center">
<FONT COLOR=blue><TT>module</TT> <FONT COLOR=maroon><TT><I>unit-name</I></TT></FONT> <TT>:</TT> <TT>sig</TT> <FONT COLOR=maroon><TT><I>unit-interface</I></TT></FONT> <TT>end</TT> <TT>=</TT>
<TT>struct</TT> <FONT COLOR=maroon><TT><I>unit-implementation</I></TT></FONT> <TT>end</TT></FONT>
</DIV><BR>
<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 CLASS="center">
<FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT> <TT>sig</TT></FONT> <FONT COLOR=maroon><I><TT>interface</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>end</TT></FONT> …
<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>:</TT> <TT>sig</TT></FONT> <I><FONT COLOR=maroon><TT>interface</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>end</TT></FONT>
</DIV>
where <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> are the names of the other
compilation units available in the search path (see
chapter <A HREF="manual022.html#c:camlc">8</A> for more details) and <FONT COLOR=maroon><I><TT>interface</TT></I></FONT><SUB>1</SUB> …
<I><FONT COLOR=maroon><TT>interface</TT></FONT><SUB>n</SUB></I> are their respective interfaces.
<HR>
<A HREF="manual019.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
</BODY>
</HTML>
|