File: modules.html

package info (click to toggle)
ocaml-doc 4.11-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 20,580 kB
  • sloc: sh: 37; makefile: 11
file content (235 lines) | stat: -rw-r--r-- 25,745 bytes parent folder | download
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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.11  Module expressions (module implementations)</title>
</head>
<body>
<a href="modtypes.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="language.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="compunit.html"><img src="next_motif.svg" alt="Next"></a>
<hr>
<h2 class="section" id="s:module-expr"><a class="section-anchor" href="#s:module-expr" aria-hidden="true"></a>7.11  Module expressions (module implementations)</h2>
<ul>
<li><a href="modules.html#ss%3Amexpr-simple">7.11.1  Simple module expressions</a>
</li><li><a href="modules.html#ss%3Amexpr-structures">7.11.2  Structures</a>
</li><li><a href="modules.html#ss%3Amexpr-functors">7.11.3  Functors</a>
</li></ul>
<p>Module expressions are the module-level equivalent of value
expressions: they evaluate to modules, thus providing implementations
for the specifications expressed in module types.</p><p><a id="hevea_manual.kwd179"></a>
<a id="hevea_manual.kwd180"></a>
<a id="hevea_manual.kwd181"></a>
<a id="hevea_manual.kwd182"></a>
<a id="hevea_manual.kwd183"></a>
<a id="hevea_manual.kwd184"></a>
<a id="hevea_manual.kwd185"></a>
<a id="hevea_manual.kwd186"></a>
<a id="hevea_manual.kwd187"></a>
<a id="hevea_manual.kwd188"></a>
<a id="hevea_manual.kwd189"></a>
<a id="hevea_manual.kwd190"></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-expr"><span class="c010">module-expr</span></a></td><td class="c015">::=</td><td class="c017">
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">struct</span> [ <a class="syntax" href="#module-items"><span class="c010">module-items</span></a> ] <span class="c004">end</span>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">functor</span> <span class="c004">(</span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> <span class="c004">)</span> <span class="c004">-&gt;</span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> <span class="c004">(</span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> <span class="c004">)</span>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">(</span> <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> <span class="c004">)</span>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">(</span> <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> <span class="c004">)</span>
 </td></tr>
<tr><td class="c018">&nbsp;</td></tr>
<tr><td class="c018">
<a class="syntax" id="module-items"><span class="c010">module-items</span></a></td><td class="c015">::=</td><td class="c017">
{<span class="c004">;;</span>} ( <a class="syntax" href="#definition"><span class="c010">definition</span></a> ∣  <a class="syntax" href="expr.html#expr"><span class="c010">expr</span></a> )  { {<span class="c004">;;</span>} ( <a class="syntax" href="#definition"><span class="c010">definition</span></a> ∣  <span class="c004">;;</span> <a class="syntax" href="expr.html#expr"><span class="c010">expr</span></a>) }  {<span class="c004">;;</span>}
 </td></tr>
<tr><td class="c018">&nbsp;</td></tr>
<tr><td class="c018">
<a class="syntax" id="definition"><span class="c010">definition</span></a></td><td class="c015">::=</td><td class="c017">
<span class="c004">let</span> [<span class="c004">rec</span>] <a class="syntax" href="expr.html#let-binding"><span class="c010">let-binding</span></a>  { <span class="c004">and</span> <a class="syntax" href="expr.html#let-binding"><span class="c010">let-binding</span></a> }
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">external</span> <a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a> <span class="c004">:</span>  <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> <span class="c004">=</span>  <a class="syntax" href="intfc.html#external-declaration"><span class="c010">external-declaration</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <a class="syntax" href="typedecl.html#type-definition"><span class="c010">type-definition</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <a class="syntax" href="typedecl.html#exception-definition"><span class="c010">exception-definition</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <a class="syntax" href="classes.html#class-definition"><span class="c010">class-definition</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <a class="syntax" href="classes.html#classtype-definition"><span class="c010">classtype-definition</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">module</span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>  { <span class="c004">(</span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> <span class="c004">)</span> }
 [ <span class="c004">:</span> <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> ]  <span class="c004">=</span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">module</span> <span class="c004">type</span> <a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a> <span class="c004">=</span>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">open</span> <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>
 </td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">∣</td><td class="c017"> <span class="c004">include</span> <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>
</td></tr>
</table></td></tr>
</table></div><p>
See also the following language extensions:
<a href="manual024.html#s%3Arecursive-modules">recursive modules</a>,
<a href="firstclassmodules.html#s%3Afirst-class-modules">first-class modules</a>,
<a href="overridingopen.html#s%3Aexplicit-overriding-open">overriding in open statements</a>,
<a href="attributes.html#s%3Aattributes">attributes</a>,
<a href="extensionnodes.html#s%3Aextension-nodes">extension nodes</a> and
<a href="generativefunctors.html#s%3Agenerative-functors">generative functors</a>.</p>
<h3 class="subsection" id="ss:mexpr-simple"><a class="section-anchor" href="#ss:mexpr-simple" aria-hidden="true"></a>7.11.1  Simple module expressions</h3>
<p>The expression <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> evaluates to the module bound to the name
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>.</p><p>The expression <span class="c004">(</span> <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> <span class="c004">)</span> evaluates to the same module as
<a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>.</p><p>The expression <span class="c004">(</span> <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> <span class="c004">)</span> checks that the
type of <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> is a subtype of <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>, that is, that all
components specified in <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> are implemented in
<a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>, and their implementation meets the requirements given
in <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>. In other terms, it checks that the implementation
<a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> meets the type specification <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>. The whole
expression evaluates to the same module as <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>, except that
all components not specified in <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> are hidden and can no
longer be accessed.</p>
<h3 class="subsection" id="ss:mexpr-structures"><a class="section-anchor" href="#ss:mexpr-structures" aria-hidden="true"></a>7.11.2  Structures</h3>
<p><a id="hevea_manual.kwd191"></a>
<a id="hevea_manual.kwd192"></a></p><p>Structures <span class="c004">struct</span> … <span class="c004">end</span> 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 scopes 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.</p><p>For compatibility with toplevel phrases (chapter <a href="toplevel.html#c%3Acamllight">10</a>),
optional <span class="c004">;;</span> are allowed after and before each definition in a structure. These
<span class="c004">;;</span> have no semantic meanings. Similarly, an <a class="syntax" href="expr.html#expr"><span class="c010">expr</span></a> preceded by <span class="c003">;;</span> is allowed as
a component of a structure. It is equivalent to <span class="c002"><span class="c003">let</span> <span class="c003">_</span> <span class="c003">=</span></span> <a class="syntax" href="expr.html#expr"><span class="c010">expr</span></a>, i.e. <a class="syntax" href="expr.html#expr"><span class="c010">expr</span></a> is
evaluated for its side-effects but is not bound to any identifier. If <a class="syntax" href="expr.html#expr"><span class="c010">expr</span></a> is
the first component of a structure, the preceding <span class="c003">;;</span> can be omitted.</p><h4 class="subsubsection" id="sss:mexpr-value-defs"><a class="section-anchor" href="#sss:mexpr-value-defs" aria-hidden="true"></a>Value definitions</h4>
<p><a id="hevea_manual.kwd193"></a></p><p>A value definition <span class="c004">let</span> [<span class="c004">rec</span>] <a class="syntax" href="expr.html#let-binding"><span class="c010">let-binding</span></a>  { <span class="c004">and</span> <a class="syntax" href="expr.html#let-binding"><span class="c010">let-binding</span></a> }
bind value names in the same way as a <span class="c004">let</span> … <span class="c004">in</span> … expression
(see section <a href="expr.html#sss%3Aexpr-localdef">7.7.2</a>). The value names appearing in the
left-hand sides of the bindings are bound to the corresponding values
in the right-hand sides.</p><p><a id="hevea_manual.kwd194"></a></p><p>A value definition <span class="c004">external</span> <a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a> <span class="c004">:</span>  <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> <span class="c004">=</span>  <a class="syntax" href="intfc.html#external-declaration"><span class="c010">external-declaration</span></a>
implements <a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a> as the external function specified in
<a class="syntax" href="intfc.html#external-declaration"><span class="c010">external-declaration</span></a> (see chapter <a href="intfc.html#c%3Aintf-c">20</a>).</p><h4 class="subsubsection" id="sss:mexpr-type-defs"><a class="section-anchor" href="#sss:mexpr-type-defs" aria-hidden="true"></a>Type definitions</h4>
<p><a id="hevea_manual.kwd195"></a></p><p>A definition of one or several type components is written
<span class="c004">type</span> <a class="syntax" href="typedecl.html#typedef"><span class="c010">typedef</span></a>  { <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><h4 class="subsubsection" id="sss:mexpr-exn-defs"><a class="section-anchor" href="#sss:mexpr-exn-defs" aria-hidden="true"></a>Exception definitions</h4>
<p><a id="hevea_manual.kwd196"></a></p><p>Exceptions are defined with the syntax <span class="c004">exception</span> <a class="syntax" href="typedecl.html#constr-decl"><span class="c010">constr-decl</span></a>
or <span class="c004">exception</span> <a class="syntax" href="names.html#constr-name"><span class="c010">constr-name</span></a> <span class="c004">=</span>  <a class="syntax" href="names.html#constr"><span class="c010">constr</span></a>.</p><h4 class="subsubsection" id="sss:mexpr-class-defs"><a class="section-anchor" href="#sss:mexpr-class-defs" aria-hidden="true"></a>Class definitions</h4>
<p><a id="hevea_manual.kwd197"></a></p><p>A definition of one or several classes is written <span class="c004">class</span>
<a class="syntax" href="classes.html#class-binding"><span class="c010">class-binding</span></a>  { <span class="c004">and</span> <a class="syntax" href="classes.html#class-binding"><span class="c010">class-binding</span></a> } and consists of a sequence of
mutually recursive definitions of class names. Class definitions are
described more precisely in section <a href="classes.html#ss%3Aclass-def">7.9.3</a>.</p><h4 class="subsubsection" id="sss:mexpr-classtype-defs"><a class="section-anchor" href="#sss:mexpr-classtype-defs" aria-hidden="true"></a>Class type definitions</h4>
<p><a id="hevea_manual.kwd198"></a>
<a id="hevea_manual.kwd199"></a></p><p>A definition of one or several classes 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 definitions are described more precisely in
section <a href="classes.html#ss%3Aclasstype">7.9.5</a>.</p><h4 class="subsubsection" id="sss:mexpr-module-defs"><a class="section-anchor" href="#sss:mexpr-module-defs" aria-hidden="true"></a>Module definitions</h4>
<p><a id="hevea_manual.kwd200"></a></p><p>The basic form for defining a module component is
<span class="c004">module</span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c004">=</span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>, which evaluates <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> and binds
the result to the name <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>.</p><p>One can 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>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> <span class="c004">=</span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</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">(</span></span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> <span class="c004">)</span>.
</div><p>
Another derived form is
</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>  <span class="c010">name</span><sub>1</sub> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a><sub>1</sub> <span class="c004">)</span> …
<span class="c004">(</span>  <span class="c010">name</span><sub><span class="c009">n</span></sub> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#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>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>
</div><p>
which is equivalent to
</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>  <span class="c010">name</span><sub>1</sub> <span class="c004">:</span>  <a class="syntax" href="modtypes.html#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> …
<span class="c004">-&gt;</span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>
</div><h4 class="subsubsection" id="sss:mexpr-modtype-defs"><a class="section-anchor" href="#sss:mexpr-modtype-defs" aria-hidden="true"></a>Module type definitions</h4>
<p><a id="hevea_manual.kwd201"></a>
<a id="hevea_manual.kwd202"></a></p><p>A definition for a module type is written
<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>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>.
It binds the name <a class="syntax" href="names.html#modtype-name"><span class="c010">modtype-name</span></a> to the module type denoted by the
expression <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>.</p><h4 class="subsubsection" id="sss:mexpr-open"><a class="section-anchor" href="#sss:mexpr-open" aria-hidden="true"></a>Opening a module path</h4>
<p><a id="hevea_manual.kwd203"></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 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 <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>  <span class="c010">name</span>. The scope of
the <span class="c004">open</span> stops at the end of the structure expression.</p><h4 class="subsubsection" id="sss:mexpr-include"><a class="section-anchor" href="#sss:mexpr-include" aria-hidden="true"></a>Including the components of another structure</h4>
<p><a id="hevea_manual.kwd204"></a></p><p>The expression <span class="c004">include</span> <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> in a structure re-exports in
the current structure all definitions of the structure denoted by
<a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a>. For instance, if you define a module <span class="c003">S</span> as below


</p><div class="caml-example verbatim">

<div class="ocaml">



<div class="pre caml-input"> <span class="ocamlkeyword">module</span> S = <span class="ocamlkeyword">struct</span> <span class="ocamlkeyword">type</span> t = int  <span class="ocamlkeyword">let</span> x = 2 <span class="ocamlkeyword">end</span></div></div>

</div><p>


defining the module <span class="c003">B</span> as


</p><div class="caml-example verbatim">

<div class="ocaml">



<div class="pre caml-input"> <span class="ocamlkeyword">module</span> B = <span class="ocamlkeyword">struct</span> <span class="ocamlkeyword">include</span> S  <span class="ocamlkeyword">let</span> y = (x + 1 : t) <span class="ocamlkeyword">end</span></div></div>

</div><p>


is equivalent to defining it as


</p><div class="caml-example verbatim">

<div class="ocaml">



<div class="pre caml-input"> <span class="ocamlkeyword">module</span> B = <span class="ocamlkeyword">struct</span> <span class="ocamlkeyword">type</span> t = S.t  <span class="ocamlkeyword">let</span> x = S.x  <span class="ocamlkeyword">let</span> y = (x + 1 : t) <span class="ocamlkeyword">end</span></div></div>

</div><p>


The difference between <span class="c004">open</span> and <span class="c004">include</span> is that <span class="c004">open</span>
simply provides short names for the components of the opened
structure, without defining any components of the current structure,
while <span class="c004">include</span> also adds definitions for the components of the
included structure.</p>
<h3 class="subsection" id="ss:mexpr-functors"><a class="section-anchor" href="#ss:mexpr-functors" aria-hidden="true"></a>7.11.3  Functors</h3>
<h4 class="subsubsection" id="sss:mexpr-functor-defs"><a class="section-anchor" href="#sss:mexpr-functor-defs" aria-hidden="true"></a>Functor definition</h4>
<p><a id="hevea_manual.kwd205"></a></p><p>The 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>  <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a> <span class="c002"><span class="c003">)</span> <span class="c003">-&gt;</span></span>
 <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> evaluates to a functor that takes as argument modules of
the type <a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a><sub>1</sub>, binds <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> to these modules,
evaluates <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a> 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).</p><h4 class="subsubsection" id="sss:mexpr-functor-app"><a class="section-anchor" href="#sss:mexpr-functor-app" aria-hidden="true"></a>Functor application</h4>
<p>The expression <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a><sub>1</sub> <span class="c004">(</span>  <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a><sub>2</sub> <span class="c004">)</span> evaluates
<a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a><sub>1</sub> to a functor and <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a><sub>2</sub> to a module, and
applies the former to the latter. The type of <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a><sub>2</sub> must
match the type expected for the arguments of the functor <a class="syntax" href="#module-expr"><span class="c010">module-expr</span></a><sub>1</sub>.</p>
<hr>
<a href="modtypes.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="language.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="compunit.html"><img src="next_motif.svg" alt="Next"></a>
</body>
</html>