~ubuntu-branches/ubuntu/hardy/ocaml-doc/hardy

« back to all changes in this revision

Viewing changes to ocaml.html/manual004.html

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2007-09-08 01:49:22 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070908014922-lvihyehz0ndq7suu
Tags: 3.10-1
* New upstream release.
* Removed camlp4 documentation since it is not up-to-date.
* Updated to standards version 3.7.2, no changes needed.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
<HTML>
4
4
<HEAD>
5
5
 
6
 
 
7
 
 
8
6
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
9
 
<META name="GENERATOR" content="hevea 1.08">
 
7
<META name="GENERATOR" content="hevea 1.09">
10
8
<LINK rel="stylesheet" type="text/css" href="manual.css">
11
 
<TITLE>
12
 
The module system
13
 
</TITLE>
 
9
<TITLE>The module system</TITLE>
14
10
</HEAD>
15
11
<BODY >
16
 
<A HREF="manual003.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
17
 
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
18
 
<A HREF="manual005.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
12
<A HREF="manual003.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
 
13
<A HREF="index.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
 
14
<A HREF="manual005.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
19
15
<HR>
20
 
 
21
 
<H1 CLASS="chapter"><A NAME="htoc12">Chapter&nbsp;2</A>&nbsp;&nbsp;The module system</H1> <A NAME="c:moduleexamples"></A>
22
 
 
23
 
This chapter introduces the module system of Objective Caml.<BR>
24
 
<BR>
25
 
 
26
 
<H2 CLASS="section"><A NAME="htoc13">2.1</A>&nbsp;&nbsp;Structures</H2>
27
 
 
28
 
A primary motivation for modules is to package together related
 
16
<H1 CLASS="chapter"><A NAME="htoc12">Chapter�2</A>��The module system</H1><P> <A NAME="c:moduleexamples"></A>
 
17
</P><P>This chapter introduces the module system of Objective Caml.</P><H2 CLASS="section"><A NAME="htoc13">2.1</A>��Structures</H2><P>A primary motivation for modules is to package together related
29
18
definitions (such as the definitions of a data type and associated
30
19
operations over that type) and enforce a consistent naming scheme for
31
20
these definitions. This avoids running out of names or accidentally
32
21
confusing names. Such a package is called a <EM>structure</EM> and
33
 
is introduced by the <TT>struct</TT>...<TT>end</TT> construct, which contains an
 
22
is introduced by the <TT>struct</TT>&#X2026;<TT>end</TT> construct, which contains an
34
23
arbitrary sequence of definitions. The structure is usually given a
35
24
name with the <TT>module</TT> binding. Here is for instance a structure
36
25
packaging together a type of priority queues and their operations:
37
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module PrioQueue =
 
26
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module PrioQueue =
38
27
   struct
39
28
     type priority = int
40
29
     type 'a queue = Empty | Node of priority * 'a * 'a queue * 'a queue
70
59
    val remove_top : 'a queue -&gt; 'a queue
71
60
    val extract : 'a queue -&gt; priority * 'a * 'a queue
72
61
  end
73
 
</FONT></PRE>
 
62
</FONT></PRE><P>
74
63
Outside the structure, its components can be referred to using the
75
 
&#8220;dot notation&#8221;, that is, identifiers qualified by a structure name.
 
64
&#X201C;dot notation&#X201D;, that is, identifiers qualified by a structure name.
76
65
For instance, <TT>PrioQueue.insert</TT> in a value context is
77
66
the function <TT>insert</TT> defined inside the structure
78
67
<TT>PrioQueue</TT>. Similarly, <TT>PrioQueue.queue</TT> in a type context is the
79
68
type <TT>queue</TT> defined in <TT>PrioQueue</TT>. 
80
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>PrioQueue.insert PrioQueue.empty 1 "hello";;
 
69
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>PrioQueue.insert PrioQueue.empty 1 "hello";;
81
70
</FONT><FONT COLOR=maroon>- : string PrioQueue.queue =
82
71
PrioQueue.Node (1, "hello", PrioQueue.Empty, PrioQueue.Empty)
83
 
</FONT></PRE>
84
 
 
85
 
<H2 CLASS="section"><A NAME="htoc14">2.2</A>&nbsp;&nbsp;Signatures</H2>
86
 
 
87
 
Signatures are interfaces for structures. A signature specifies
 
72
</FONT></PRE><H2 CLASS="section"><A NAME="htoc14">2.2</A>��Signatures</H2><P>Signatures are interfaces for structures. A signature specifies
88
73
which components of a structure are accessible from the outside, and
89
74
with which type. It can be used to hide some components of a structure 
90
75
(e.g. local function definitions) or export some components with a
92
77
priority queue operations <TT>empty</TT>, <TT>insert</TT> and <TT>extract</TT>, but not the
93
78
auxiliary function <TT>remove_top</TT>. Similarly, it makes the <TT>queue</TT> type
94
79
abstract (by not providing its actual representation as a concrete type).
95
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module type PRIOQUEUE =
 
80
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module type PRIOQUEUE =
96
81
   sig
97
82
     type priority = int         (* still concrete *)
98
83
     type 'a queue               (* now abstract *)
110
95
    val extract : 'a queue -&gt; int * 'a * 'a queue
111
96
    exception Queue_is_empty
112
97
  end
113
 
</FONT></PRE>
 
98
</FONT></PRE><P>
114
99
Restricting the <TT>PrioQueue</TT> structure by this signature results in
115
100
another view of the <TT>PrioQueue</TT> structure where the <TT>remove_top</TT>
116
101
function is not accessible and the actual representation of priority
117
102
queues is hidden:
118
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module AbstractPrioQueue = (PrioQueue : PRIOQUEUE);;
 
103
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module AbstractPrioQueue = (PrioQueue : PRIOQUEUE);;
119
104
</FONT><FONT COLOR=maroon>module AbstractPrioQueue : PRIOQUEUE
120
 
&nbsp;
 
105
121
106
<FONT COLOR=black>#</FONT><FONT COLOR=blue><U>AbstractPrioQueue.remove_top</U>;;
122
107
</FONT>Unbound value AbstractPrioQueue.remove_top
123
 
&nbsp;
 
108
124
109
<FONT COLOR=black>#</FONT><FONT COLOR=blue>AbstractPrioQueue.insert AbstractPrioQueue.empty 1 "hello";;
125
110
</FONT>- : string AbstractPrioQueue.queue = &lt;abstr&gt;
126
 
</FONT></PRE>
 
111
</FONT></PRE><P>
127
112
The restriction can also be performed during the definition of the
128
113
structure, as in
129
 
<PRE CLASS="verbatim">
130
 
module PrioQueue = (struct ... end : PRIOQUEUE);;
131
 
</PRE>An alternate syntax is provided for the above:
132
 
<PRE CLASS="verbatim">
133
 
module PrioQueue : PRIOQUEUE = struct ... end;;
134
 
</PRE>
135
 
 
136
 
<H2 CLASS="section"><A NAME="htoc15">2.3</A>&nbsp;&nbsp;Functors</H2>
137
 
 
138
 
Functors are &#8220;functions&#8221; from structures to structures. They are used to
 
114
</P><PRE CLASS="verbatim">module PrioQueue = (struct ... end : PRIOQUEUE);;
 
115
</PRE><P>An alternate syntax is provided for the above:
 
116
</P><PRE CLASS="verbatim">module PrioQueue : PRIOQUEUE = struct ... end;;
 
117
</PRE><H2 CLASS="section"><A NAME="htoc15">2.3</A>��Functors</H2><P>Functors are &#X201C;functions&#X201D; from structures to structures. They are used to
139
118
express parameterized structures: a structure <I>A</I> parameterized by a
140
119
structure <I>B</I> is simply a functor <I>F</I> with a formal parameter
141
120
<I>B</I> (along with the expected signature for <I>B</I>) which returns
142
121
the actual structure <I>A</I> itself. The functor <I>F</I> can then be
143
 
applied to one or several implementations <I>B</I><SUB>1</SUB> ...<I>B<SUB>n</SUB></I>
 
122
applied to one or several implementations <I>B</I><SUB>1</SUB> &#X2026;<I>B<SUB>n</SUB></I>
144
123
of <I>B</I>, yielding the corresponding structures
145
 
<I>A</I><SUB>1</SUB> ...<I>A<SUB>n</SUB></I>.<BR>
146
 
<BR>
147
 
For instance, here is a structure implementing sets as sorted lists,
 
124
<I>A</I><SUB>1</SUB> &#X2026;<I>A<SUB>n</SUB></I>.</P><P>For instance, here is a structure implementing sets as sorted lists,
148
125
parameterized by a structure providing the type of the set elements
149
126
and an ordering function over this type (used to keep the sets
150
127
sorted):
151
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>type comparison = Less | Equal | Greater;;
 
128
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>type comparison = Less | Equal | Greater;;
152
129
</FONT><FONT COLOR=maroon>type comparison = Less | Equal | Greater
153
 
&nbsp;
 
130
154
131
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module type ORDERED_TYPE =
155
132
   sig
156
133
     type t
157
134
     val compare: t -&gt; t -&gt; comparison
158
135
   end;;
159
136
</FONT>module type ORDERED_TYPE = sig type t val compare : t -&gt; t -&gt; comparison end
160
 
&nbsp;
 
137
161
138
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module Set =
162
139
   functor (Elt: ORDERED_TYPE) -&gt;
163
140
     struct
190
167
      val add : Elt.t -&gt; Elt.t list -&gt; Elt.t list
191
168
      val member : Elt.t -&gt; Elt.t list -&gt; bool
192
169
    end
193
 
</FONT></PRE>
 
170
</FONT></PRE><P>
194
171
By applying the <TT>Set</TT> functor to a structure implementing an ordered
195
172
type, we obtain set operations for this type:
196
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module OrderedString =
 
173
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module OrderedString =
197
174
   struct
198
175
     type t = string
199
176
     let compare x y = if x = y then Equal else if x &lt; y then Less else Greater
200
177
   end;;
201
178
</FONT><FONT COLOR=maroon>module OrderedString :
202
179
  sig type t = string val compare : 'a -&gt; 'a -&gt; comparison end
203
 
&nbsp;
 
180
204
181
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module StringSet = Set(OrderedString);;
205
182
</FONT>module StringSet :
206
183
  sig
210
187
    val add : OrderedString.t -&gt; OrderedString.t list -&gt; OrderedString.t list
211
188
    val member : OrderedString.t -&gt; OrderedString.t list -&gt; bool
212
189
  end
213
 
&nbsp;
 
190
214
191
<FONT COLOR=black>#</FONT><FONT COLOR=blue>StringSet.member "bar" (StringSet.add "foo" StringSet.empty);;
215
192
</FONT>- : bool = false
216
 
</FONT></PRE>
217
 
 
218
 
<H2 CLASS="section"><A NAME="htoc16">2.4</A>&nbsp;&nbsp;Functors and type abstraction</H2>
219
 
 
220
 
As in the <TT>PrioQueue</TT> example, it would be good style to hide the
 
193
</FONT></PRE><H2 CLASS="section"><A NAME="htoc16">2.4</A>��Functors and type abstraction</H2><P>As in the <TT>PrioQueue</TT> example, it would be good style to hide the
221
194
actual implementation of the type <TT>set</TT>, so that users of the
222
195
structure will not rely on sets being lists, and we can switch later
223
196
to another, more efficient representation of sets without breaking
224
197
their code. This can be achieved by restricting <TT>Set</TT> by a suitable
225
198
functor signature:
226
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module type SETFUNCTOR =
 
199
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module type SETFUNCTOR =
227
200
   functor (Elt: ORDERED_TYPE) -&gt;
228
201
     sig
229
202
       type element = Elt.t      (* concrete *)
241
214
      val add : element -&gt; set -&gt; set
242
215
      val member : element -&gt; set -&gt; bool
243
216
    end
244
 
&nbsp;
 
217
245
218
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module AbstractSet = (Set : SETFUNCTOR);;
246
219
</FONT>module AbstractSet : SETFUNCTOR
247
 
&nbsp;
 
220
248
221
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module AbstractStringSet = AbstractSet(OrderedString);;
249
222
</FONT>module AbstractStringSet :
250
223
  sig
254
227
    val add : element -&gt; set -&gt; set
255
228
    val member : element -&gt; set -&gt; bool
256
229
  end
257
 
&nbsp;
 
230
258
231
<FONT COLOR=black>#</FONT><FONT COLOR=blue>AbstractStringSet.add "gee" AbstractStringSet.empty;;
259
232
</FONT>- : AbstractStringSet.set = &lt;abstr&gt;
260
 
</FONT></PRE>
261
 
In an attempt to write the type constraint above more elegantly,
 
233
</FONT></PRE><P>In an attempt to write the type constraint above more elegantly,
262
234
one may wish to name the signature of the structure
263
235
returned by the functor, then use that signature in the constraint:
264
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module type SET =
 
236
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module type SET =
265
237
   sig
266
238
     type element
267
239
     type set
277
249
    val add : element -&gt; set -&gt; set
278
250
    val member : element -&gt; set -&gt; bool
279
251
  end
280
 
&nbsp;
 
252
281
253
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module WrongSet = (Set : functor(Elt: ORDERED_TYPE) -&gt; SET);;
282
254
</FONT>module WrongSet : functor (Elt : ORDERED_TYPE) -&gt; SET
283
 
&nbsp;
 
255
284
256
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module WrongStringSet = WrongSet(OrderedString);;
285
257
</FONT>module WrongStringSet :
286
258
  sig
290
262
    val add : element -&gt; set -&gt; set
291
263
    val member : element -&gt; set -&gt; bool
292
264
  end
293
 
&nbsp;
 
265
294
266
<FONT COLOR=black>#</FONT><FONT COLOR=blue>WrongStringSet.add <U>"gee"</U> WrongStringSet.empty;;
295
267
</FONT>This expression has type string but is here used with type
296
268
  WrongStringSet.element = WrongSet(OrderedString).element
297
 
</FONT></PRE>
 
269
</FONT></PRE><P>
298
270
The problem here is that <TT>SET</TT> specifies the type <TT>element</TT>
299
271
abstractly, so that the type equality between <TT>element</TT> in the result
300
272
of the functor and <TT>t</TT> in its argument is forgotten. Consequently,
306
278
not exist. To overcome this difficulty, Objective Caml provides a
307
279
<TT>with type</TT> construct over signatures that allows to enrich a signature
308
280
with extra type equalities:
309
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module AbstractSet = 
 
281
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module AbstractSet = 
310
282
   (Set : functor(Elt: ORDERED_TYPE) -&gt; (SET with type element = Elt.t));;
311
283
</FONT><FONT COLOR=maroon>module AbstractSet :
312
284
  functor (Elt : ORDERED_TYPE) -&gt;
317
289
      val add : element -&gt; set -&gt; set
318
290
      val member : element -&gt; set -&gt; bool
319
291
    end
320
 
</FONT></PRE>
321
 
As in the case of simple structures, an alternate syntax is provided
 
292
</FONT></PRE><P>As in the case of simple structures, an alternate syntax is provided
322
293
for defining functors and restricting their result:
323
 
<PRE CLASS="verbatim">
324
 
module AbstractSet(Elt: ORDERED_TYPE) : (SET with type element = Elt.t) =
 
294
</P><PRE CLASS="verbatim">module AbstractSet(Elt: ORDERED_TYPE) : (SET with type element = Elt.t) =
325
295
  struct ... end;;
326
 
</PRE>
327
 
Abstracting a type component in a functor result is a powerful
 
296
</PRE><P>Abstracting a type component in a functor result is a powerful
328
297
technique that provides a high degree of type safety, as we now
329
298
illustrate. Consider an ordering over character strings that is
330
299
different from the standard ordering implemented in the
331
300
<TT>OrderedString</TT> structure. For instance, we compare strings without
332
301
distinguishing upper and lower case.
333
 
<PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module NoCaseString =
 
302
</P><PRE><FONT COLOR=black>#</FONT><FONT COLOR=blue>module NoCaseString =
334
303
   struct
335
304
     type t = string
336
305
     let compare s1 s2 =
338
307
   end;;
339
308
</FONT><FONT COLOR=maroon>module NoCaseString :
340
309
  sig type t = string val compare : string -&gt; string -&gt; comparison end
341
 
&nbsp;
 
310
342
311
<FONT COLOR=black>#</FONT><FONT COLOR=blue>module NoCaseStringSet = AbstractSet(NoCaseString);;
343
312
</FONT>module NoCaseStringSet :
344
313
  sig
348
317
    val add : element -&gt; set -&gt; set
349
318
    val member : element -&gt; set -&gt; bool
350
319
  end
351
 
&nbsp;
 
320
352
321
<FONT COLOR=black>#</FONT><FONT COLOR=blue>NoCaseStringSet.add "FOO" <U>AbstractStringSet.empty</U>;;
353
322
</FONT>This expression has type
354
323
  AbstractStringSet.set = AbstractSet(OrderedString).set
355
324
but is here used with type
356
325
  NoCaseStringSet.set = AbstractSet(NoCaseString).set
357
 
</FONT></PRE>
 
326
</FONT></PRE><P>
358
327
Notice that the two types <TT>AbstractStringSet.set</TT> and 
359
328
<TT>NoCaseStringSet.set</TT> are not compatible, and values of these
360
329
two types do not match. This is the correct behavior: even though both
364
333
standard ordering and for the case-insensitive ordering). Applying
365
334
operations from <TT>AbstractStringSet</TT> to values of type
366
335
<TT>NoCaseStringSet.set</TT> could give incorrect results, or build
367
 
lists that violate the invariants of <TT>NoCaseStringSet</TT>.<BR>
368
 
<BR>
369
 
 
370
 
<H2 CLASS="section"><A NAME="htoc17">2.5</A>&nbsp;&nbsp;Modules and separate compilation</H2>
371
 
 
372
 
All examples of modules so far have been given in the context of the
 
336
lists that violate the invariants of <TT>NoCaseStringSet</TT>.</P><H2 CLASS="section"><A NAME="htoc17">2.5</A>��Modules and separate compilation</H2><P>All examples of modules so far have been given in the context of the
373
337
interactive system. However, modules are most useful for large,
374
338
batch-compiled programs. For these programs, it is a practical
375
339
necessity to split the source into several files, called compilation
376
340
units, that can be compiled separately, thus minimizing recompilation
377
 
after changes.<BR>
378
 
<BR>
379
 
In Objective Caml, compilation units are special cases of structures
 
341
after changes.</P><P>In Objective Caml, compilation units are special cases of structures
380
342
and signatures, and the relationship between the units can be
381
343
explained easily in terms of the module system. A compilation unit <I>A</I>
382
344
comprises two files:
383
 
<UL CLASS="itemize"><LI CLASS="li-itemize">
 
345
</P><UL CLASS="itemize"><LI CLASS="li-itemize">
384
346
the implementation file <I>A</I><TT>.ml</TT>, which contains a sequence
385
 
of definitions, analogous to the inside of a <TT>struct</TT>...<TT>end</TT>
 
347
of definitions, analogous to the inside of a <TT>struct</TT>&#X2026;<TT>end</TT>
386
348
construct;
387
 
<LI CLASS="li-itemize">the interface file <I>A</I><TT>.mli</TT>, which contains a sequence of
388
 
specifications, analogous to the inside of a <TT>sig</TT>...<TT>end</TT>
 
349
</LI><LI CLASS="li-itemize">the interface file <I>A</I><TT>.mli</TT>, which contains a sequence of
 
350
specifications, analogous to the inside of a <TT>sig</TT>&#X2026;<TT>end</TT>
389
351
construct.
390
 
</UL>
 
352
</LI></UL><P>
391
353
Both files define a structure named <I>A</I> as if
392
354
the following definition was entered at top-level:
393
 
<PRE>
 
355
</P><PRE>
394
356
module <I>A</I>: sig (* contents of file <I>A</I>.mli *) end
395
357
        = struct (* contents of file <I>A</I>.ml *) end;;
396
 
</PRE>
 
358
</PRE><P>
397
359
The files defining the compilation units can be compiled separately
398
 
using the <TT>ocamlc -c</TT> command (the <TT>-c</TT> option means &#8220;compile only, do
399
 
not try to link&#8221;); this produces compiled interface files (with
 
360
using the <TT>ocamlc -c</TT> command (the <TT>-c</TT> option means &#X201C;compile only, do
 
361
not try to link&#X201D;); this produces compiled interface files (with
400
362
extension <TT>.cmi</TT>) and compiled object code files (with extension
401
363
<TT>.cmo</TT>). When all units have been compiled, their <TT>.cmo</TT> files are
402
364
linked together using the <TT>ocaml</TT> command. For instance, the following
403
365
commands compile and link a program composed of two compilation units
404
366
<TT>Aux</TT> and <TT>Main</TT>:
405
 
<PRE CLASS="verbatim">
406
 
$ ocamlc -c Aux.mli                     # produces aux.cmi
 
367
</P><PRE CLASS="verbatim">$ ocamlc -c Aux.mli                     # produces aux.cmi
407
368
$ ocamlc -c Aux.ml                      # produces aux.cmo
408
369
$ ocamlc -c Main.mli                    # produces main.cmi
409
370
$ ocamlc -c Main.ml                     # produces main.cmo
410
371
$ ocamlc -o theprogram Aux.cmo Main.cmo
411
 
</PRE>The program behaves exactly as if the following phrases were entered
 
372
</PRE><P>The program behaves exactly as if the following phrases were entered
412
373
at top-level:
413
 
<PRE>
 
374
</P><PRE>
414
375
module Aux: sig (* contents of Aux.mli *) end
415
376
          = struct (* contents of Aux.ml *) end;;
416
377
module Main: sig (* contents of Main.mli *) end
417
378
           = struct (* contents of Main.ml *) end;;
418
 
</PRE>
 
379
</PRE><P>
419
380
In particular, <TT>Main</TT> can refer to <TT>Aux</TT>: the definitions and
420
381
declarations contained in <TT>Main.ml</TT> and <TT>Main.mli</TT> can refer to
421
382
definition in <TT>Aux.ml</TT>, using the <TT>Aux.</TT><I>ident</I> notation, provided
422
 
these definitions are exported in <TT>Aux.mli</TT>.<BR>
423
 
<BR>
424
 
The order in which the <TT>.cmo</TT> files are given to <TT>ocaml</TT> during the
 
383
these definitions are exported in <TT>Aux.mli</TT>.</P><P>The order in which the <TT>.cmo</TT> files are given to <TT>ocaml</TT> during the
425
384
linking phase determines the order in which the module definitions
426
385
occur. Hence, in the example above, <TT>Aux</TT> appears first and <TT>Main</TT> can
427
 
refer to it, but <TT>Aux</TT> cannot refer to <TT>Main</TT>.<BR>
428
 
<BR>
429
 
Notice that only top-level structures can be mapped to
 
386
refer to it, but <TT>Aux</TT> cannot refer to <TT>Main</TT>.</P><P>Notice that only top-level structures can be mapped to
430
387
separately-compiled files, but not functors nor module types.
431
388
However, all module-class objects can appear as components of a
432
389
structure, so the solution is to put the functor or module type
433
390
inside a structure, which can then be mapped to a file.
434
391
 
435
 
<BR>
436
 
<BR>
437
 
<HR>
438
 
<A HREF="manual003.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
439
 
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
440
 
<A HREF="manual005.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
 
392
</P><HR>
 
393
<A HREF="manual003.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
 
394
<A HREF="index.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
 
395
<A HREF="manual005.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
441
396
</BODY>
442
397
</HTML>