Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > 19bb6433bb07a8b16410504336791904 > files > 226

ocaml-doc-3.06-5mdk.ppc.rpm

<!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.06-7 of 2001-11-14">
<TITLE>
 Module expressions (module implementations)
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="manual018.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual020.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc85"><B><FONT SIZE=5>6.11</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Module expressions (module implementations)</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE> <A NAME="s:module-expr"></A>
<BR>
Module expressions are the module-level equivalent of value
expressions: they evaluate to modules, thus providing implementations
for the specifications expressed in module types.<BR>
<BR>
<A NAME="@manual.kwd142"></A>
<A NAME="@manual.kwd143"></A>
<A NAME="@manual.kwd144"></A>
<A NAME="@manual.kwd145"></A>
<A NAME="@manual.kwd146"></A>
<A NAME="@manual.kwd147"></A>
<A NAME="@manual.kwd148"></A>
<A NAME="@manual.kwd149"></A>
<A NAME="@manual.kwd150"></A>
<A NAME="@manual.kwd151"></A>
<A NAME="@manual.kwd152"></A><BR>
<DIV ALIGN=center><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><I><FONT COLOR=maroon>module-path</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>struct</FONT></TT> { <TT><I><FONT COLOR=maroon>definition</FONT></I></TT> &nbsp;[<TT><FONT COLOR=blue>;;</FONT></TT>] } <TT><FONT COLOR=blue>end</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>functor</FONT></TT> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT> <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> <TT><FONT COLOR=blue>(</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<TT><I><FONT COLOR=maroon>definition</FONT></I></TT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <TT><FONT COLOR=blue>let</FONT></TT> [<TT><FONT COLOR=blue>rec</FONT></TT>] <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>external</FONT></TT> <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>external-declaration</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>type-definition</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>exception-definition</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>class-definition</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><I><FONT COLOR=maroon>classtype-definition</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT> }
 &nbsp;[ <TT><FONT COLOR=blue>:</FONT></TT> <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> ]</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=left NOWRAP><TT><FONT COLOR=blue>=</FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>module</FONT></TT> <TT><FONT COLOR=blue>type</FONT></TT> <TT><I><FONT COLOR=maroon>modtype-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>open</FONT></TT> <TT><I><FONT COLOR=maroon>module-path</FONT></I></TT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>|</TD>
<TD ALIGN=left NOWRAP> <TT><FONT COLOR=blue>include</FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT></TD>
</TR></TABLE></DIV><BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc86"><B><FONT SIZE=4>6.11.1</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Simple module expressions</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The expression <TT><I><FONT COLOR=maroon>module-path</FONT></I></TT> evaluates to the module bound to the name
<TT><I><FONT COLOR=maroon>module-path</FONT></I></TT>.<BR>
<BR>
The expression <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT> evaluates to the same module as
<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>.<BR>
<BR>
The expression <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT> checks that the
type of <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> is a subtype of <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT>, that is, that all
components specified in <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> are implemented in
<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>, and their implementation meets the requirements given
in <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT>. In other terms, it checks that the implementation
<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> meets the type specification <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT>. The whole
expression evaluates to the same module as <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>, except that
all components not specified in <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> are hidden and can no
longer be accessed.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc87"><B><FONT SIZE=4>6.11.2</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Structures</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd153"></A>
<A NAME="@manual.kwd154"></A><BR>
Structures <TT><FONT COLOR=blue>struct</FONT></TT> ... <TT><FONT COLOR=blue>end</FONT></TT> are collections of definitions for
value names, type names, exceptions, module names and module type
names. The definitions are evaluated in the order in which they appear
in the structure. The scope of the bindings performed by the
definitions extend to the end of the structure. As a consequence, a
definition may refer to names bound by earlier definitions in the same
structure.<BR>
<BR>
For compatibility with toplevel phrases (chapter&nbsp;<A HREF="manual023.html#c:camllight">9</A>)
and with Caml Light, an optional <TT>;;</TT> is allowed after each
definition in a structure. The <TT>;;</TT> has no semantic meaning. Also for
compatibility, <TT><FONT COLOR=blue>;;</FONT></TT> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT> is allowed as a component of a structure,
meaning <TT><FONT COLOR=blue>let</FONT></TT> <TT><FONT COLOR=blue>_</FONT></TT> <TT><FONT COLOR=blue>=</FONT></TT> <TT><I><FONT COLOR=maroon>expr</FONT></I></TT>, i.e. evaluate <TT><I><FONT COLOR=maroon>expr</FONT></I></TT> for its side-effects.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Value definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd155"></A><BR>
A value definition <TT><FONT COLOR=blue>let</FONT></TT> [<TT><FONT COLOR=blue>rec</FONT></TT>] <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>let-binding</FONT></I></TT> }
bind value names in the same way as a <TT><FONT COLOR=blue>let</FONT></TT> ... <TT><FONT COLOR=blue>in</FONT></TT> ... expression
(see section&nbsp;<A HREF="manual015.html#s:localdef">6.7.1</A>). The value names appearing in the
left-hand sides of the bindings are bound to the corresponding values
in the right-hand sides.<BR>
<BR>
<A NAME="@manual.kwd156"></A><BR>
<BR>
A value definition <TT><FONT COLOR=blue>external</FONT></TT> <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>typexpr</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>external-declaration</FONT></I></TT>
implements <TT><I><FONT COLOR=maroon>value-name</FONT></I></TT> as the external function specified in
<TT><I><FONT COLOR=maroon>external-declaration</FONT></I></TT> (see chapter&nbsp;<A HREF="manual032.html#c:intf-c">18</A>).<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Type definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd157"></A><BR>
A definition of one or several type components is written
<TT><FONT COLOR=blue>type</FONT></TT> <TT><I><FONT COLOR=maroon>typedef</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>typedef</FONT></I></TT> } and consists of a sequence
of mutually recursive definitions of type names.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Exception definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd158"></A><BR>
Exceptions are defined with the syntax <TT><FONT COLOR=blue>exception</FONT></TT> <TT><I><FONT COLOR=maroon>constr-decl</FONT></I></TT>
or <TT><FONT COLOR=blue>exception</FONT></TT> <TT><I><FONT COLOR=maroon>constr-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>constr</FONT></I></TT>.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Class definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd159"></A><BR>
A definition of one or several classes is written <TT><FONT COLOR=blue>class</FONT></TT>
<TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>class-binding</FONT></I></TT> } and consists of a sequence of
mutually recursive definitions of class names. Class definitions are
described more precisely in section&nbsp;<A HREF="manual017.html#s:classdef">6.9.3</A>.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Class type definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd160"></A>
<A NAME="@manual.kwd161"></A><BR>
A definition of one or several classes is written
<TT><FONT COLOR=blue>class</FONT></TT> <TT><FONT COLOR=blue>type</FONT></TT> <TT><I><FONT COLOR=maroon>classtype-def</FONT></I></TT> &nbsp;{ <TT><FONT COLOR=blue>and</FONT></TT> <TT><I><FONT COLOR=maroon>classtype-def</FONT></I></TT> } and consists of
a sequence of mutually recursive definitions of class type names.
Class type definitions are described more precisely in
section&nbsp;<A HREF="manual017.html#s:classtype">6.9.5</A>.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Module definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd162"></A><BR>
The basic form for defining a module component is
<TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>, which evaluates <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> and binds
the result to the name <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT>.<BR>
<BR>
One can write
<DIV ALIGN=center>
<TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>
</DIV>
instead of
<DIV ALIGN=center>
<TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> <TT><FONT COLOR=blue>(</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT>.
</DIV>
Another derived form is
<DIV ALIGN=center>
<TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>(</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>name</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>)</FONT></TT> ...
 <TT><FONT COLOR=blue>(</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>name</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT><SUB><FONT SIZE=2><I>n</I></FONT></SUB> <TT><FONT COLOR=blue>)</FONT></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>
</DIV>
which is equivalent to
<DIV ALIGN=center>
<TT><FONT COLOR=blue>module</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT>
 <TT><FONT COLOR=blue>functor</FONT></TT> <TT><FONT COLOR=blue>(</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>name</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>)</FONT></TT> <TT><FONT COLOR=blue>-&gt;</FONT></TT> ...
 <TT><FONT COLOR=blue>-&gt;</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>
</DIV><BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Module type definitions</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd163"></A>
<A NAME="@manual.kwd164"></A><BR>
A definition for a module type is written
<TT><FONT COLOR=blue>module</FONT></TT> <TT><FONT COLOR=blue>type</FONT></TT> <TT><I><FONT COLOR=maroon>modtype-name</FONT></I></TT> <TT><FONT COLOR=blue>=</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT>.
It binds the name <TT><I><FONT COLOR=maroon>modtype-name</FONT></I></TT> to the module type denoted by the
expression <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT>.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Opening a module path</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd165"></A><BR>
The expression <TT><FONT COLOR=blue>open</FONT></TT> <TT><I><FONT COLOR=maroon>module-path</FONT></I></TT> in a structure does not define any
components nor perform any bindings. It simply affects the parsing of
the following items of the structure, allowing components of the
module denoted by <TT><I><FONT COLOR=maroon>module-path</FONT></I></TT> to be referred to by their simple names
<TT><I><FONT COLOR=maroon>name</FONT></I></TT> instead of path accesses <TT><I><FONT COLOR=maroon>module-path</FONT></I></TT> <TT><FONT COLOR=blue>.</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>name</FONT></I></TT>. The scope of
the <TT>open</TT> stops at the end of the structure expression.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Including the components of another structure</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd166"></A><BR>
The expression <TT><FONT COLOR=blue>include </FONT></TT> <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> in a structure re-exports in
the current structure all definitions of the structure denoted by
<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT>. For instance, if the identifier <TT>S</TT> is bound to the
module
<PRE>
        struct type t = int  let x = 2 end
</PRE>the module expression
<PRE>
        struct include S  let y = (x + 1 : t) end
</PRE>is equivalent to the module expression
<PRE>
        struct type t = int  let x = 2  let y = (x + 1 : t) end
</PRE>The difference between <TT><FONT COLOR=blue>open</FONT></TT> and <TT><FONT COLOR=blue>include</FONT></TT> is that <TT><FONT COLOR=blue>open</FONT></TT>
simply provides short names for the components of the opened
structure, without defining any components of the current structure,
while <TT><FONT COLOR=blue>include</FONT></TT> also adds definitions for the components of the
included structure.<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#7fff7f"><DIV ALIGN=center><TABLE>
<TR><TD><A NAME="htoc88"><B><FONT SIZE=4>6.11.3</FONT></B></A></TD>
<TD WIDTH="100%" ALIGN=center><B><FONT SIZE=4>Functors</FONT></B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Functor definition</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
<A NAME="@manual.kwd167"></A><BR>
The expression <TT><FONT COLOR=blue>functor</FONT></TT> <TT><FONT COLOR=blue>(</FONT></TT> <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> <TT><FONT COLOR=blue>:</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-type</FONT></I></TT> <TT><FONT COLOR=blue>)</FONT></TT> <TT><FONT COLOR=blue>-&gt;</FONT></TT>
&nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> evaluates to a functor that takes as argument modules of
the type <TT><I><FONT COLOR=maroon>module-type</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB>, binds <TT><I><FONT COLOR=maroon>module-name</FONT></I></TT> to these modules,
evaluates <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT> in the extended environment, and returns the
resulting modules as results. No restrictions are placed on the type of the
functor argument; in particular, a functor may take another functor as
argument (``higher-order'' functor).<BR>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#98ff98"><DIV ALIGN=center><TABLE>
<TR><TD><B>Functor application</B></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE><BR>
The expression <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> <TT><FONT COLOR=blue>(</FONT></TT> &nbsp;<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT><SUB><FONT SIZE=2>2</FONT></SUB> <TT><FONT COLOR=blue>)</FONT></TT> evaluates
<TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB> to a functor and <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT><SUB><FONT SIZE=2>2</FONT></SUB> to a module, and
applies the former to the latter. The type of <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT><SUB><FONT SIZE=2>2</FONT></SUB> must
match the type expected for the arguments of the functor <TT><I><FONT COLOR=maroon>module-expr</FONT></I></TT><SUB><FONT SIZE=2>1</FONT></SUB>.<BR>
<BR>

<BR>
<BR>
<HR>
<A HREF="manual018.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual020.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>