Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > fb18813323b88f9a6e869238ab603257 > files > 506

ocaml-doc-4.07.1-2.mga7.noarch.rpm

<!DOCTYPE html>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="generator" content="hevea 2.32">

  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="manual.css">
<title>7.10&#XA0;&#XA0;Module types (module specifications)</title>
</head>
<body>
<a href="classes.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="language.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="modules.html"><img src="next_motif.svg" alt="Next"></a>
<hr>
<h2 class="section" id="sec202">7.10&#XA0;&#XA0;Module types (module specifications)</h2>
<ul>
<li><a href="modtypes.html#sec203">7.10.1&#XA0;&#XA0;Simple module types</a>
</li><li><a href="modtypes.html#sec204">7.10.2&#XA0;&#XA0;Signatures</a>
</li><li><a href="modtypes.html#sec214">7.10.3&#XA0;&#XA0;Functor types</a>
</li><li><a href="modtypes.html#sec215">7.10.4&#XA0;&#XA0;The <span class="c003">with</span> operator</a>
</li></ul>
<p>Module types are the module-level equivalent of type expressions: they
specify the general shape and type properties of modules.</p><p><a id="hevea_manual.kwd148"></a>
<a id="hevea_manual.kwd149"></a>
<a id="hevea_manual.kwd150"></a>
<a id="hevea_manual.kwd151"></a>
<a id="hevea_manual.kwd152"></a>
<a id="hevea_manual.kwd153"></a>
<a id="hevea_manual.kwd154"></a>
<a id="hevea_manual.kwd155"></a>
<a id="hevea_manual.kwd156"></a>
<a id="hevea_manual.kwd157"></a>
<a id="hevea_manual.kwd158"></a>
<a id="hevea_manual.kwd159"></a>
<a id="hevea_manual.kwd160"></a></p><div class="syntax"><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018">
<a class="syntax" id="module-type"><span class="c010">module-type</span></a></td><td class="c015">::=</td><td class="c017">
<a class="syntax" href="names.html#modtype-path"><span class="c010">modtype-path</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">sig</span>&#XA0;{&#XA0;<a class="syntax" href="#specification"><span class="c010">specification</span></a>&#XA0;&#XA0;[<span class="c004">;;</span>]&#XA0;}&#XA0;<span class="c004">end</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">functor</span>&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>&#XA0;<span class="c004">)</span>&#XA0;<span class="c004">-&gt;</span>&#XA0;&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>&#XA0;<span class="c004">-&gt;</span>&#XA0;&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>&#XA0;<span class="c004">with</span>&#XA0;&#XA0;<a class="syntax" href="#mod-constraint"><span class="c010">mod-constraint</span></a>&#XA0;&#XA0;{&#XA0;<span class="c004">and</span>&#XA0;<a class="syntax" href="#mod-constraint"><span class="c010">mod-constraint</span></a>&#XA0;}
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td></tr>
<tr><td class="c018">
<a class="syntax" id="mod-constraint"><span class="c010">mod-constraint</span></a></td><td class="c015">::=</td><td class="c017">
<span class="c004">type</span>&#XA0;[<a class="syntax" href="typedecl.html#type-params"><span class="c010">type-params</span></a>]&#XA0;&#XA0;<a class="syntax" href="names.html#typeconstr"><span class="c010">typeconstr</span></a>&#XA0;&#XA0;<a class="syntax" href="typedecl.html#type-equation"><span class="c010">type-equation</span></a>&#XA0;&#XA0;{&#XA0;<a class="syntax" href="typedecl.html#type-constraint"><span class="c010">type-constraint</span></a>&#XA0;}
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">module</span>&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="names.html#extended-module-path"><span class="c010">extended-module-path</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td></tr>
</table></td></tr>
</table></div><div class="syntax"><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018">
<a class="syntax" id="specification"><span class="c010">specification</span></a></td><td class="c015">::=</td><td class="c017">
<span class="c004">val</span>&#XA0;<a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">external</span>&#XA0;<a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="intfc.html#external-declaration"><span class="c010">external-declaration</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="typedecl.html#type-definition"><span class="c010">type-definition</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">exception</span>&#XA0;<a class="syntax" href="typedecl.html#constr-decl"><span class="c010">constr-decl</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="classes.html#class-specification"><span class="c010">class-specification</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="classes.html#classtype-definition"><span class="c010">classtype-definition</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">module</span>&#XA0;<a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">module</span>&#XA0;<a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>&#XA0;&#XA0;{&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>&#XA0;<span class="c004">)</span>&#XA0;}
<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">module</span>&#XA0;<span class="c004">type</span>&#XA0;<a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">module</span>&#XA0;<span class="c004">type</span>&#XA0;<a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">open</span>&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">include</span>&#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
</td></tr>
</table></td></tr>
</table></div><p>
See also the following language extensions:
<a href="extn.html#s%3Amodule-type-of">recovering the type of a module</a>,
<a href="extn.html#s%3Asignature-substitution">substitution inside a signature</a>,
<a href="extn.html#s%3Amodule-alias">type-level module aliases</a>,
<a href="extn.html#s%3Aattributes">attributes</a>,
<a href="extn.html#s%3Aextension-nodes">extension nodes</a> and
<a href="extn.html#s%3Agenerative-functors">generative functors</a>.</p>
<h3 class="subsection" id="sec203">7.10.1&#XA0;&#XA0;Simple module types</h3>
<p>The expression <a class="syntax" href="names.html#modtype-path"><span class="c010">modtype-path</span></a> is equivalent to the module type bound
to the name <a class="syntax" href="names.html#modtype-path"><span class="c010">modtype-path</span></a>.
The expression <span class="c004">(</span> <a class="syntax" href="#module-type"><span class="c010">module-type</span></a> <span class="c004">)</span> denotes the same type as
<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>.</p>
<h3 class="subsection" id="sec204">7.10.2&#XA0;&#XA0;Signatures</h3>
<p><a id="hevea_manual.kwd161"></a>
<a id="hevea_manual.kwd162"></a></p><p>Signatures are type specifications for structures. Signatures
<span class="c004">sig</span> &#X2026; <span class="c004">end</span> are collections of type specifications for value
names, type names, exceptions, module names and module type names. A
structure will match a signature if the structure provides definitions
(implementations) for all the names specified in the signature (and
possibly more), and these definitions meet the type requirements given
in the signature.</p><p>An optional <span class="c004">;;</span> is allowed after each specification in a
signature. It serves as a syntactic separator with no semantic
meaning.</p><h4 class="subsubsection" id="sec205">Value specifications</h4>
<p><a id="hevea_manual.kwd163"></a></p><p>A specification of a value component in a signature is written
<span class="c004">val</span> <a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>, where <a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a> is the name of the
value and <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> its expected type.</p><p><a id="hevea_manual.kwd164"></a></p><p>The form <span class="c004">external</span> <a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> <span class="c004">=</span> &#XA0;<a class="syntax" href="intfc.html#external-declaration"><span class="c010">external-declaration</span></a>
is similar, except that it requires in addition the name to be
implemented as the external function specified in <a class="syntax" href="intfc.html#external-declaration"><span class="c010">external-declaration</span></a>
(see chapter&#XA0;<a href="intfc.html#c%3Aintf-c">20</a>).</p><h4 class="subsubsection" id="sec206">Type specifications</h4>
<p><a id="hevea_manual.kwd165"></a></p><p>A specification of one or several type components in a signature is
written <span class="c004">type</span> <a class="syntax" href="typedecl.html#typedef"><span class="c010">typedef</span></a> &#XA0;{ <span class="c004">and</span> <a class="syntax" href="typedecl.html#typedef"><span class="c010">typedef</span></a> } and consists of a sequence
of mutually recursive definitions of type names.</p><p>Each type definition in the signature specifies an optional type
equation <span class="c004">=</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> and an optional type representation
<span class="c004">=</span> <a class="syntax" href="typedecl.html#constr-decl"><span class="c010">constr-decl</span></a> &#X2026; or <span class="c002"><span class="c003">=</span> <span class="c003">{</span></span> <a class="syntax" href="typedecl.html#field-decl"><span class="c010">field-decl</span></a> &#X2026; <span class="c004">}</span>.
The implementation of the type name in a matching structure must
be compatible with the type expression specified in the equation (if
given), and have the specified representation (if given). Conversely,
users of that signature will be able to rely on the type equation
or type representation, if given. More precisely, we have the
following four situations:</p><dl class="description"><dt class="dt-description">
<span class="c013">Abstract type: no equation, no representation.</span></dt><dd class="dd-description"> &#XA0; <br>
Names that are defined as abstract types in a signature can be
implemented in a matching structure by any kind of type definition
(provided it has the same number of type parameters). The exact
implementation of the type will be hidden to the users of the
structure. In particular, if the type is implemented as a variant type
or record type, the associated constructors and fields will not be
accessible to the users; if the type is implemented as an
abbreviation, the type equality between the type name and the
right-hand side of the abbreviation will be hidden from the users of the
structure. Users of the structure consider that type as incompatible
with any other type: a fresh type has been generated.</dd><dt class="dt-description"><span class="c013">Type abbreviation: an equation </span><span class="c004">=</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><span class="c013">, no representation.</span></dt><dd class="dd-description"> &#XA0; <br>
The type name must be implemented by a type compatible with <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>.
All users of the structure know that the type name is
compatible with <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>.</dd><dt class="dt-description"><span class="c013">New variant type or record type: no equation, a representation.</span></dt><dd class="dd-description"> &#XA0; <br>
The type name must be implemented by a variant type or record type
with exactly the constructors or fields specified. All users of the
structure have access to the constructors or fields, and can use them
to create or inspect values of that type. However, users of the
structure consider that type as incompatible with any other type: a
fresh type has been generated.</dd><dt class="dt-description"><span class="c013">Re-exported variant type or record type: an equation,
a representation.</span></dt><dd class="dd-description"> &#XA0; <br>
This case combines the previous two: the representation of the type is
made visible to all users, and no fresh type is generated.
</dd></dl><h4 class="subsubsection" id="sec207">Exception specification</h4>
<p><a id="hevea_manual.kwd166"></a></p><p>The specification <span class="c004">exception</span> <a class="syntax" href="typedecl.html#constr-decl"><span class="c010">constr-decl</span></a> in a signature requires the
matching structure to provide an exception with the name and arguments
specified in the definition, and makes the exception available to all
users of the structure.</p><h4 class="subsubsection" id="sec208">Class specifications</h4>
<p><a id="hevea_manual.kwd167"></a></p><p>A specification of one or several classes in a signature is written
<span class="c004">class</span> <a class="syntax" href="classes.html#class-spec"><span class="c010">class-spec</span></a> &#XA0;{ <span class="c004">and</span> <a class="syntax" href="classes.html#class-spec"><span class="c010">class-spec</span></a> } and consists of a sequence
of mutually recursive definitions of class names.</p><p>Class specifications are described more precisely in
section&#XA0;<a href="classes.html#s%3Aclass-spec">7.9.4</a>.</p><h4 class="subsubsection" id="sec209">Class type specifications</h4>
<p><a id="hevea_manual.kwd168"></a>
<a id="hevea_manual.kwd169"></a></p><p>A specification of one or several classe types in a signature is
written <span class="c002"><span class="c003">class</span> <span class="c003">type</span></span> <a class="syntax" href="classes.html#classtype-def"><span class="c010">classtype-def</span></a> { <span class="c004">and</span> <a class="syntax" href="classes.html#classtype-def"><span class="c010">classtype-def</span></a> } and
consists of a sequence of mutually recursive definitions of class type
names. Class type specifications are described more precisely in
section&#XA0;<a href="classes.html#s%3Aclasstype">7.9.5</a>.</p><h4 class="subsubsection" id="sec210">Module specifications</h4>
<p><a id="hevea_manual.kwd170"></a></p><p>A specification of a module component in a signature is written
<span class="c004">module</span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>, where <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> is the
name of the module component and <a class="syntax" href="#module-type"><span class="c010">module-type</span></a> its expected type.
Modules can be nested arbitrarily; in particular, functors can appear
as components of structures and functor types as components of
signatures.</p><p>For specifying a module component that is a functor, one may write
</p><div class="center">
<span class="c004">module</span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c004">(</span> &#XA0;<span class="c010">name</span><sub>1</sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>1</sub> <span class="c004">)</span>
&#X2026; <span class="c004">(</span> &#XA0;<span class="c010">name</span><sub><span class="c009">n</span></sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub><span class="c009">n</span></sub> <span class="c002"><span class="c003">)</span>
<span class="c003">:</span></span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
</div><p>
instead of
</p><div class="center">
<span class="c004">module</span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c002"><span class="c003">:</span>
<span class="c003">functor</span> <span class="c003">(</span></span> &#XA0;<span class="c010">name</span><sub>1</sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>1</sub> <span class="c002"><span class="c003">)</span> <span class="c003">-&gt;</span></span> &#X2026;
<span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
</div><h4 class="subsubsection" id="sec211">Module type specifications</h4>
<p><a id="hevea_manual.kwd171"></a>
<a id="hevea_manual.kwd172"></a></p><p>A module type component of a signature can be specified either as a
manifest module type or as an abstract module type.</p><p>An abstract module type specification
<span class="c002"><span class="c003">module</span> <span class="c003">type</span></span> <a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a> allows the name <a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a> to be
implemented by any module type in a matching signature, but hides the
implementation of the module type to all users of the signature.</p><p>A manifest module type specification
<span class="c002"><span class="c003">module</span> <span class="c003">type</span></span> <a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a> <span class="c004">=</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a>
requires the name <a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a> to be implemented by the module type
<a class="syntax" href="#module-type"><span class="c010">module-type</span></a> in a matching signature, but makes the equality between
<a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a> and <a class="syntax" href="#module-type"><span class="c010">module-type</span></a> apparent to all users of the signature.</p>
<h4 class="subsubsection" id="sec212">Opening a module path</h4>
<p><a id="hevea_manual.kwd173"></a></p><p>The expression <span class="c004">open</span> <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> in a signature does not specify
any components. It simply affects the parsing of the following items
of the signature, allowing components of the module denoted by
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> to be referred to by their simple names <span class="c010">name</span> instead of
path accesses <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> <span class="c004">.</span> &#XA0;<span class="c010">name</span>. The scope of the <span class="c004">open</span>
stops at the end of the signature expression.</p>
<h4 class="subsubsection" id="sec213">Including a signature</h4>
<p><a id="hevea_manual.kwd174"></a></p><p>The expression <span class="c004">include</span> <a class="syntax" href="#module-type"><span class="c010">module-type</span></a> in a signature performs textual
inclusion of the components of the signature denoted by <a class="syntax" href="#module-type"><span class="c010">module-type</span></a>.
It behaves as if the components of the included signature were copied
at the location of the <span class="c004">include</span>. The <a class="syntax" href="#module-type"><span class="c010">module-type</span></a> argument must
refer to a module type that is a signature, not a functor type.</p>
<h3 class="subsection" id="sec214">7.10.3&#XA0;&#XA0;Functor types</h3>
<p><a id="hevea_manual.kwd175"></a></p><p>The module type expression
<span class="c002"><span class="c003">functor</span> <span class="c003">(</span></span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>1</sub> <span class="c002"><span class="c003">)</span> <span class="c003">-&gt;</span></span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>2</sub>
is the type of functors (functions from modules to modules) that take
as argument a module of type <a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>1</sub> and return as result a
module of type <a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>2</sub>. The module type <a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>2</sub> can
use the name <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> to refer to type components of the actual
argument of the functor. If the type <a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>2</sub> does not
depend on type components of <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>, the module type expression
can be simplified with the alternative short syntax
 <a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>1</sub> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#module-type"><span class="c010">module-type</span></a><sub>2</sub> .
No restrictions are placed on the type of the functor argument; in
particular, a functor may take another functor as argument
(&#X201C;higher-order&#X201D; functor).</p>
<h3 class="subsection" id="sec215">7.10.4&#XA0;&#XA0;The <span class="c003">with</span> operator</h3>
<p><a id="hevea_manual.kwd176"></a></p><p>Assuming <a class="syntax" href="#module-type"><span class="c010">module-type</span></a> denotes a signature, the expression
<a class="syntax" href="#module-type"><span class="c010">module-type</span></a> <span class="c004">with</span> &#XA0;<a class="syntax" href="#mod-constraint"><span class="c010">mod-constraint</span></a> { <span class="c004">and</span> <a class="syntax" href="#mod-constraint"><span class="c010">mod-constraint</span></a> } denotes
the same signature where type equations have been added to some of the
type specifications, as described by the constraints following the
<span class="c003">with</span> keyword. The constraint <span class="c004">type</span> [<a class="syntax" href="classes.html#type-parameters"><span class="c010">type-parameters</span></a>] &#XA0;<a class="syntax" href="names.html#typeconstr"><span class="c010">typeconstr</span></a>
<span class="c004">=</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> adds the type equation <span class="c004">=</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> to the specification
of the type component named <a class="syntax" href="names.html#typeconstr"><span class="c010">typeconstr</span></a> of the constrained signature.
The constraint <span class="c004">module</span> <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> <span class="c004">=</span> &#XA0;<a class="syntax" href="names.html#extended-module-path"><span class="c010">extended-module-path</span></a> adds
type equations to all type components of the sub-structure denoted by
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>, making them equivalent to the corresponding type
components of the structure denoted by <a class="syntax" href="names.html#extended-module-path"><span class="c010">extended-module-path</span></a>.</p><p>For instance, if the module type name <span class="c003">S</span> is bound to the signature
</p><pre>        sig type t module M: (sig type u end) end
</pre><p>then <span class="c003">S with type t=int</span> denotes the signature
</p><pre>        sig type t=int module M: (sig type u end) end
</pre><p>and <span class="c003">S with module M = N</span> denotes the signature
</p><pre>        sig type t module M: (sig type u=N.u end) end
</pre><p>A functor taking two arguments of type <span class="c003">S</span> that share their <span class="c003">t</span> component
is written
</p><pre>        functor (A: S) (B: S with type t = A.t) ...
</pre><p>
Constraints are added left to right. After each constraint has been
applied, the resulting signature must be a subtype of the signature
before the constraint was applied. Thus, the <span class="c004">with</span> operator can
only add information on the type components of a signature, but never
remove information.

</p>
<hr>
<a href="classes.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="language.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="modules.html"><img src="next_motif.svg" alt="Next"></a>
</body>
</html>