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
|
<!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.09">
<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><TABLE CLASS="display dcenter"><TR VALIGN="middle"><TD CLASS="dcell"><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=right NOWRAP>
<I><A NAME="unit-interface"><FONT COLOR=maroon>unit-interface</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>{<I><A HREF="manual018.html#specification"><FONT COLOR=maroon>specification</FONT></A></I>[<FONT COLOR=blue><TT>;;</TT></FONT>]}
</TD></TR>
<TR><TD ALIGN=right NOWRAP> </TD></TR>
<TR><TD ALIGN=right NOWRAP>
<I><A NAME="unit-implementation"><FONT COLOR=maroon>unit-implementation</FONT></A></I></TD><TD ALIGN=center NOWRAP>::=</TD><TD ALIGN=left NOWRAP>{<I><A HREF="manual019.html#definition"><FONT COLOR=maroon>definition</FONT></A></I>[<FONT COLOR=blue><TT>;;</TT></FONT>]}</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 <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>unit-name</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
</P><DIV CLASS="center">
<FONT COLOR=blue><TT>module</TT> <FONT COLOR=maroon><I>unit-name</I></FONT> <TT>:</TT> <TT>sig</TT></FONT> <I><A HREF="#unit-interface"><FONT COLOR=maroon>unit-interface</FONT></A></I> <FONT COLOR=blue><TT>end</TT> <TT>=</TT>
<TT>struct</TT></FONT> <I><A HREF="#unit-implementation"><FONT COLOR=maroon>unit-implementation</FONT></A></I> <FONT COLOR=blue><TT>end</TT></FONT>
</DIV><P>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
</P><DIV CLASS="center">
<FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT> <TT>sig</TT></FONT> <I><A HREF="manual018.html#specification"><FONT COLOR=maroon>specification</FONT></A></I><SUB>1</SUB> <FONT COLOR=blue><TT>end</TT></FONT> …
<I><FONT COLOR=maroon>name</FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>:</TT> <TT>sig</TT></FONT> <I><A HREF="manual018.html#specification"><FONT COLOR=maroon>specification</FONT></A><SUB>n</SUB></I> <FONT COLOR=blue><TT>end</TT></FONT>
</DIV><P>
where <FONT COLOR=maroon><I>name</I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon>name</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 <I><A HREF="manual018.html#specification"><FONT COLOR=maroon>specification</FONT></A></I><SUB>1</SUB> …
<I><A HREF="manual018.html#specification"><FONT COLOR=maroon>specification</FONT></A><SUB>n</SUB></I> are their respective interfaces.
</P><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>
|