File: manual018.html

package info (click to toggle)
ocaml-doc 3.09-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 10,428 kB
  • ctags: 4,963
  • sloc: ml: 9,244; makefile: 2,413; ansic: 122; sh: 49; asm: 17
file content (354 lines) | stat: -rw-r--r-- 24,128 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<!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>
Module types (module specifications)
</TITLE>
</HEAD>
<BODY >
<A HREF="manual017.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual019.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc81">6.10</A>&nbsp;&nbsp;Module types (module specifications)</H2>

Module types are the module-level equivalent of type expressions: they
specify the general shape and type properties of modules.<BR>
<BR>
<A NAME="@manual.kwd115"></A>
<A NAME="@manual.kwd116"></A>
<A NAME="@manual.kwd117"></A>
<A NAME="@manual.kwd118"></A>
<A NAME="@manual.kwd119"></A>
<A NAME="@manual.kwd120"></A>
<A NAME="@manual.kwd121"></A>
<A NAME="@manual.kwd122"></A>
<A NAME="@manual.kwd123"></A>
<A NAME="@manual.kwd124"></A>
<A NAME="@manual.kwd125"></A>
<A NAME="@manual.kwd126"></A><BR>
<BR>
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<A NAME="module-type"></A>
<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <FONT COLOR=maroon><I><a href="manual011.html#modtype-path"><font color=maroon><TT>modtype-path</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>sig</TT></FONT> { <FONT COLOR=maroon><I><a href="#specification"><font color=maroon><TT>specification</TT></font></a></I></FONT> &nbsp;[<FONT COLOR=blue><TT>;;</TT></FONT>] } <FONT COLOR=blue><TT>end</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>functor</TT></FONT> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT> <FONT COLOR=blue><TT>)</TT> <TT>-&gt;</TT></FONT> &nbsp;<TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT> <FONT COLOR=blue><TT>with</TT></FONT> &nbsp;<TT><a href="#mod-constraint"><font color=maroon><I>mod-constraint</I></font></a></TT></FONT> &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="#mod-constraint"><font color=maroon><TT>mod-constraint</TT></font></a></I></FONT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="mod-constraint"></A>
<FONT COLOR=maroon><I><TT>mod-constraint</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <FONT COLOR=blue><TT>type</TT></FONT> [<FONT COLOR=maroon><I><a href="manual017.html#type-parameters"><font color=maroon><TT>type-parameters</TT></font></a></I></FONT>] &nbsp;<FONT COLOR=maroon><TT><a href="manual011.html#typeconstr"><font color=maroon><I>typeconstr</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-path"><font color=maroon><I>module-path</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="manual011.html#extended-module-path"><font color=maroon><I>extended-module-path</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="specification"></A>
<FONT COLOR=maroon><I><TT>specification</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
 <FONT COLOR=blue><TT>val</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#value-name"><font color=maroon><I>value-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>external</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#value-name"><font color=maroon><I>value-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>external-declaration</I></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual016.html#type-definition"><font color=maroon><TT>type-definition</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><I><a href="manual016.html#constr-decl"><font color=maroon><TT>constr-decl</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual017.html#class-specification"><font color=maroon><TT>class-specification</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual017.html#classtype-definition"><font color=maroon><TT>classtype-definition</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#module-name"><font color=maroon><TT>module-name</TT></font></a></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="manual011.html#module-name"><font color=maroon><I>module-name</I></font></a></TT></FONT> <TT>:</TT> &nbsp;<FONT COLOR=maroon><TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT> <TT>)</TT></FONT> }
 <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<FONT COLOR=maroon><I><a href="#module-type"><font color=maroon><TT>module-type</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT> <TT>type</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#modtype-name"><font color=maroon><TT>modtype-name</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=blue><TT>type</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#modtype-name"><font color=maroon><I>modtype-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><a href="#module-type"><font color=maroon><I>module-type</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>open</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#module-path"><font color=maroon><TT>module-path</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>&nbsp;</TD>
<TD ALIGN=right NOWRAP>&#8739;</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>include</TT></FONT> <FONT COLOR=maroon><I><a href="#module-type"><font color=maroon><TT>module-type</TT></font></a></I></FONT></TD>
</TR></TABLE></DIV><BR>
<BR>

<H3 CLASS="subsection"><A NAME="htoc82">6.10.1</A>&nbsp;&nbsp;Simple module types</H3>
The expression <FONT COLOR=maroon><I><TT>modtype-path</TT></I></FONT> is equivalent to the module type bound
to the name <FONT COLOR=maroon><I><TT>modtype-path</TT></I></FONT>.
The expression <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>module-type</I></TT></FONT> <TT>)</TT></FONT> denotes the same type as
<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>.<BR>
<BR>

<H3 CLASS="subsection"><A NAME="htoc83">6.10.2</A>&nbsp;&nbsp;Signatures</H3>
<A NAME="@manual.kwd127"></A>
<A NAME="@manual.kwd128"></A>
Signatures are type specifications for structures. Signatures
<FONT COLOR=blue><TT>sig</TT></FONT> &hellip; <FONT COLOR=blue><TT>end</TT></FONT> 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.<BR>
<BR>
For compatibility with Caml Light, an optional <TT>;;</TT> is allowed after each
specification in a signature. The <TT>;;</TT> has no semantic meaning.<BR>
<BR>

<H4 CLASS="subsubsection">Value specifications</H4>
<A NAME="@manual.kwd129"></A>
A specification of a value component in a signature is written
<FONT COLOR=blue><TT>val</TT></FONT> <FONT COLOR=maroon><TT><I>value-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>typexpr</I></TT></FONT>, where <FONT COLOR=maroon><I><TT>value-name</TT></I></FONT> is the name of the
value and <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT> its expected type.<BR>
<BR>
<A NAME="@manual.kwd130"></A><BR>
<BR>
The form <FONT COLOR=blue><TT>external</TT></FONT> <FONT COLOR=maroon><TT><I>value-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>typexpr</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>external-declaration</I></TT></FONT>
is similar, except that it requires in addition the name to be
implemented as the external function specified in <FONT COLOR=maroon><I><TT>external-declaration</TT></I></FONT>
(see chapter&nbsp;<A HREF="manual032.html#c:intf-c">18</A>).<BR>
<BR>

<H4 CLASS="subsubsection">Type specifications</H4>
<A NAME="@manual.kwd131"></A>
A specification of one or several type components in a signature is
written <FONT COLOR=blue><TT>type</TT></FONT> <FONT COLOR=maroon><I><TT>typedef</TT></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>typedef</TT></I></FONT> } and consists of a sequence
of mutually recursive definitions of type names.<BR>
<BR>
Each type definition in the signature specifies an optional type
equation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT> and an optional type representation 
<FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT> &hellip; or <FONT COLOR=blue><TT>=</TT> <TT>{</TT></FONT> <FONT COLOR=maroon><I><TT>label-decl</TT></I></FONT> &hellip; <FONT COLOR=blue><TT>}</TT></FONT>.
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:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>Abstract type: no equation, no representation.</B><DD CLASS="dd-description"> &nbsp;<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.<BR>
<BR>
<DT CLASS="dt-description"><B>Type abbreviation: an equation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><TT><I>typexp</I></TT></FONT>, no representation.</B><DD CLASS="dd-description"> &nbsp;<BR>
The type name must be implemented by a type compatible with <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT>.
All users of the structure know that the type name is
compatible with <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT>.<BR>
<BR>
<DT CLASS="dt-description"><B>New variant type or record type: no equation, a representation.</B><DD CLASS="dd-description"> &nbsp;<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.<BR>
<BR>
<DT CLASS="dt-description"><B>Re-exported variant type or record type: an equation,
a representation.</B><DD CLASS="dd-description"> &nbsp;<BR>
This case combines the previous two: the representation of the type is
made visible to all users, and no fresh type is generated.
</DL>

<H4 CLASS="subsubsection">Exception specification</H4>
<A NAME="@manual.kwd132"></A>
The specification <FONT COLOR=blue><TT>exception</TT></FONT> <FONT COLOR=maroon><I><TT>constr-decl</TT></I></FONT> 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.<BR>
<BR>

<H4 CLASS="subsubsection">Class specifications</H4>
<A NAME="@manual.kwd133"></A>
A specification of one or several classes in a signature is written
<FONT COLOR=blue><TT>class</TT></FONT> <FONT COLOR=maroon><I><TT>class-spec</TT></I></FONT> &nbsp;{ <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>class-spec</TT></I></FONT> } and consists of a sequence
of mutually recursive definitions of class names.<BR>
<BR>
Class specifications are described more precisely in
section&nbsp;<A HREF="manual017.html#s:class-spec">6.9.4</A>.<BR>
<BR>

<H4 CLASS="subsubsection">Class type specifications</H4>
<A NAME="@manual.kwd134"></A>
<A NAME="@manual.kwd135"></A>
A specification of one or several classe types in a signature is
written <FONT COLOR=blue><TT>class</TT> <TT>type</TT></FONT> <FONT COLOR=maroon><I><TT>classtype-def</TT></I></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>classtype-def</TT></I></FONT> } and
consists of a sequence of mutually recursive definitions of class type
names. Class type specifications are described more precisely in
section&nbsp;<A HREF="manual017.html#s:classtype">6.9.5</A>.<BR>
<BR>

<H4 CLASS="subsubsection">Module specifications</H4>
<A NAME="@manual.kwd136"></A>
A specification of a module component in a signature is written
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>module-type</I></TT></FONT>, where <FONT COLOR=maroon><I><TT>module-name</TT></I></FONT> is the
name of the module component and <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> its expected type.
Modules can be nested arbitrarily; in particular, functors can appear
as components of structures and functor types as components of
signatures.<BR>
<BR>
For specifying a module component that is a functor, one may write
<DIV CLASS="center">
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>(</TT></FONT> &nbsp;<TT><I>name</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT></FONT>
 &hellip; <FONT COLOR=blue><TT>(</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<I><FONT COLOR=maroon><TT>module-type</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>)</TT>
 <TT>:</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>
</DIV>
instead of
<DIV CLASS="center">
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>:</TT>
 <TT>functor</TT> <TT>(</TT></FONT> &nbsp;<TT><I>name</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT> <TT>-&gt;</TT></FONT> &hellip;
 <FONT COLOR=blue><TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>
</DIV><BR>
<BR>

<H4 CLASS="subsubsection">Module type specifications</H4>
<A NAME="@manual.kwd137"></A>
<A NAME="@manual.kwd138"></A>
A module type component of a signature can be specified either as a
manifest module type or as an abstract module type.<BR>
<BR>
An abstract module type specification
<FONT COLOR=blue><TT>module</TT> <TT>type</TT></FONT> <FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> allows the name <FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> 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.<BR>
<BR>
A manifest module type specification
<FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=blue><TT>type</TT></FONT> <FONT COLOR=maroon><TT><I>modtype-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>module-type</I></TT></FONT>
requires the name <FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> to be implemented by the module type
<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> in a matching signature, but makes the equality between
<FONT COLOR=maroon><I><TT>modtype-name</TT></I></FONT> and <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> apparent to all users of the signature.<BR>
<BR>

<H4 CLASS="subsubsection">Opening a module path</H4>
<A NAME="@manual.kwd139"></A>
The expression <FONT COLOR=blue><TT>open</TT></FONT> <FONT COLOR=maroon><I><TT>module-path</TT></I></FONT> 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
<FONT COLOR=maroon><I><TT>module-path</TT></I></FONT> to be referred to by their simple names <FONT COLOR=maroon><I><TT>name</TT></I></FONT> instead of
path accesses <FONT COLOR=maroon><TT><I>module-path</I></TT> <FONT COLOR=blue><TT>.</TT></FONT> &nbsp;<TT><I>name</I></TT></FONT>. The scope of the <TT>open</TT>
stops at the end of the signature expression.<BR>
<BR>

<H4 CLASS="subsubsection">Including a signature</H4>
<A NAME="@manual.kwd140"></A>
The expression <FONT COLOR=blue><TT>include</TT></FONT> <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> in a signature performs textual
inclusion of the components of the signature denoted by <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT>.
It behaves as if the components of the included signature were copied
at the location of the <FONT COLOR=blue><TT>include</TT></FONT>. The <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> argument must
refer to a module type that is a signature, not a functor type.<BR>
<BR>

<H3 CLASS="subsection"><A NAME="htoc84">6.10.3</A>&nbsp;&nbsp;Functor types</H3>
<A NAME="@manual.kwd141"></A>
The module type expression 
<FONT COLOR=blue><TT>functor</TT></FONT> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><I>module-name</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> &nbsp;<TT><I>module-type</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>)</TT> <TT>-&gt;</TT></FONT> &nbsp;<FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>2</SUB> 
is the type of functors (functions from modules to modules) that take
as argument a module of type <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>1</SUB> and return as result a
module of type <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>2</SUB>. The module type <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT><SUB>2</SUB> can
use the name <FONT COLOR=maroon><I><TT>module-name</TT></I></FONT> to refer to type components of the actual
argument of the functor. No restrictions are placed on the type of the
functor argument; in particular, a functor may take another functor as
argument (&#8220;higher-order&#8221; functor).<BR>
<BR>

<H3 CLASS="subsection"><A NAME="htoc85">6.10.4</A>&nbsp;&nbsp;The <TT>with</TT> operator</H3>
<A NAME="@manual.kwd142"></A>
Assuming <FONT COLOR=maroon><I><TT>module-type</TT></I></FONT> denotes a signature, the expression
<FONT COLOR=maroon><TT><I>module-type</I></TT> <FONT COLOR=blue><TT>with</TT></FONT> &nbsp;<TT><I>mod-constraint</I></TT></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><TT>mod-constraint</TT></I></FONT> } denotes
the same signature where type equations have been added to some of the
type specifications, as described by the constraints following the
<TT>with</TT> keyword. The constraint <FONT COLOR=blue><TT>type</TT></FONT> [<FONT COLOR=maroon><I><TT>type-parameters</TT></I></FONT>] &nbsp;<FONT COLOR=maroon><TT><I>typeconstr</I></TT>
<FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>typexp</I></TT></FONT> adds the type equation <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>typexp</TT></I></FONT> to the specification
of the type component named <FONT COLOR=maroon><I><TT>typeconstr</TT></I></FONT> of the constrained signature.
The constraint <FONT COLOR=blue><TT>module</TT></FONT> <FONT COLOR=maroon><TT><I>module-path</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> &nbsp;<TT><I>extended-module-path</I></TT></FONT> adds
type equations to all type components of the sub-structure denoted by
<FONT COLOR=maroon><I><TT>module-path</TT></I></FONT>, making them equivalent to the corresponding type
components of the structure denoted by <FONT COLOR=maroon><I><TT>extended-module-path</TT></I></FONT>.<BR>
<BR>
For instance, if the module type name <TT>S</TT> is bound to the signature
<PRE CLASS="verbatim">
        sig type t module M: (sig type u end) end
</PRE>then <TT>S with type t=int</TT> denotes the signature
<PRE CLASS="verbatim">
        sig type t=int module M: (sig type u end) end
</PRE>and <TT>S with module M = N</TT> denotes the signature
<PRE CLASS="verbatim">
        sig type t module M: (sig type u=N.u end) end
</PRE>A functor taking two arguments of type <TT>S</TT> that share their <TT>t</TT> component
is written
<PRE CLASS="verbatim">
        functor (A: S) (B: S with type t = A.t) ...
</PRE>
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 <FONT COLOR=blue><TT>with</TT></FONT> operator can
only add information on the type components of a signature, but never
remove information.

<BR>
<BR>
<HR>
<A HREF="manual017.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual019.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>