File: comp.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 (909 lines) | stat: -rw-r--r-- 80,652 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
<!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>Chapter 9  Batch compilation (ocamlc)</title>
</head>
<body>
<a href="extn.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="toplevel.html"><img src="next_motif.svg" alt="Next"></a>
<hr>
<h1 class="chapter" id="sec287">Chapter 9  Batch compilation (ocamlc)</h1>
<ul>
<li><a href="comp.html#s%3Acomp-overview">9.1  Overview of the compiler</a>
</li><li><a href="comp.html#s%3Acomp-options">9.2  Options</a>
</li><li><a href="comp.html#s%3Amodules-file-system">9.3  Modules and the file system</a>
</li><li><a href="comp.html#s%3Acomp-errors">9.4  Common errors</a>
</li><li><a href="comp.html#s%3Acomp-warnings">9.5  Warning reference</a>
</li></ul>
<p> <a id="c:camlc"></a>
</p><p>This chapter describes the OCaml batch compiler <span class="c003">ocamlc</span>,
which compiles OCaml source files to bytecode object files and links
these object files to produce standalone bytecode executable files.
These executable files are then run by the bytecode interpreter
<span class="c003">ocamlrun</span>.</p>
<h2 class="section" id="s:comp-overview"><a class="section-anchor" href="#s:comp-overview" aria-hidden="true"></a>9.1  Overview of the compiler</h2>
<p>The <span class="c003">ocamlc</span> command has a command-line interface similar to the one of
most C compilers. It accepts several types of arguments and processes them
sequentially, after all options have been processed:</p><ul class="itemize"><li class="li-itemize">
Arguments ending in <span class="c003">.mli</span> are taken to be source files for
compilation unit interfaces. Interfaces specify the names exported by
compilation units: they declare value names with their types, define
public data types, declare abstract data types, and so on. From the
file <span class="c009">x</span><span class="c003">.mli</span>, the <span class="c003">ocamlc</span> compiler produces a compiled interface
in the file <span class="c009">x</span><span class="c003">.cmi</span>.</li><li class="li-itemize">Arguments ending in <span class="c003">.ml</span> are taken to be source files for compilation
unit implementations. Implementations provide definitions for the
names exported by the unit, and also contain expressions to be
evaluated for their side-effects. From the file <span class="c009">x</span><span class="c003">.ml</span>, the <span class="c003">ocamlc</span>
compiler produces compiled object bytecode in the file <span class="c009">x</span><span class="c003">.cmo</span>.<p>If the interface file <span class="c009">x</span><span class="c003">.mli</span> exists, the implementation
<span class="c009">x</span><span class="c003">.ml</span> is checked against the corresponding compiled interface
<span class="c009">x</span><span class="c003">.cmi</span>, which is assumed to exist. If no interface
<span class="c009">x</span><span class="c003">.mli</span> is provided, the compilation of <span class="c009">x</span><span class="c003">.ml</span> produces a
compiled interface file <span class="c009">x</span><span class="c003">.cmi</span> in addition to the compiled
object code file <span class="c009">x</span><span class="c003">.cmo</span>. The file <span class="c009">x</span><span class="c003">.cmi</span> produced
corresponds to an interface that exports everything that is defined in
the implementation <span class="c009">x</span><span class="c003">.ml</span>.</p></li><li class="li-itemize">Arguments ending in <span class="c003">.cmo</span> are taken to be compiled object bytecode. These
files are linked together, along with the object files obtained
by compiling <span class="c003">.ml</span> arguments (if any), and the OCaml standard
library, to produce a standalone executable program. The order in
which <span class="c003">.cmo</span> and <span class="c003">.ml</span> arguments are presented on the command line is
relevant: compilation units are initialized in that order at
run-time, and it is a link-time error to use a component of a unit
before having initialized it. Hence, a given <span class="c009">x</span><span class="c003">.cmo</span> file must come
before all <span class="c003">.cmo</span> files that refer to the unit <span class="c009">x</span>.</li><li class="li-itemize">Arguments ending in <span class="c003">.cma</span> are taken to be libraries of object bytecode.
A library of object bytecode packs in a single file a set of object
bytecode files (<span class="c003">.cmo</span> files). Libraries are built with <span class="c003">ocamlc -a</span>
(see the description of the <span class="c003">-a</span> option below). The object files
contained in the library are linked as regular <span class="c003">.cmo</span> files (see
above), in the order specified when the <span class="c003">.cma</span> file was built. The
only difference is that if an object file contained in a library is
not referenced anywhere in the program, then it is not linked in.</li><li class="li-itemize">Arguments ending in <span class="c003">.c</span> are passed to the C compiler, which generates
a <span class="c003">.o</span> object file (<span class="c003">.obj</span> under Windows). This object file is linked
with the program if the <span class="c003">-custom</span> flag is set (see the description of
<span class="c003">-custom</span> below).</li><li class="li-itemize">Arguments ending in <span class="c003">.o</span> or <span class="c003">.a</span> (<span class="c003">.obj</span> or <span class="c003">.lib</span> under Windows)
are assumed to be C object files and libraries. They are passed to the
C linker when linking in <span class="c003">-custom</span> mode (see the description of
<span class="c003">-custom</span> below).</li><li class="li-itemize">Arguments ending in <span class="c003">.so</span> (<span class="c003">.dll</span> under Windows)
are assumed to be C shared libraries (DLLs). During linking, they are
searched for external C functions referenced from the OCaml code,
and their names are written in the generated bytecode executable.
The run-time system <span class="c003">ocamlrun</span> then loads them dynamically at program
start-up time.</li></ul><p>The output of the linking phase is a file containing compiled bytecode
that can be executed by the OCaml bytecode interpreter:
the command named <span class="c003">ocamlrun</span>. If <span class="c003">a.out</span> is the name of the file
produced by the linking phase, the command
</p><pre>
        ocamlrun a.out <span class="c009">arg</span><sub>1</sub> <span class="c009">arg</span><sub>2</sub> … <span class="c009">arg</span><sub><span class="c009">n</span></sub>
</pre><p>
executes the compiled code contained in <span class="c003">a.out</span>, passing it as
arguments the character strings <span class="c009">arg</span><sub>1</sub> to <span class="c009">arg</span><sub><span class="c009">n</span></sub>.
(See chapter <a href="runtime.html#c%3Aruntime">11</a> for more details.)</p><p>On most systems, the file produced by the linking
phase can be run directly, as in:
</p><pre>
        ./a.out <span class="c009">arg</span><sub>1</sub> <span class="c009">arg</span><sub>2</sub> … <span class="c009">arg</span><sub><span class="c009">n</span></sub>
</pre><p>
The produced file has the executable bit set, and it manages to launch
the bytecode interpreter by itself.</p><p>The compiler is able to emit some information on its internal stages.
It can output <span class="c003">.cmt</span> files for the implementation of the compilation unit
and <span class="c003">.cmti</span> for signatures if the option <span class="c003">-bin-annot</span> is passed to it (see the
description of <span class="c003">-bin-annot</span> below).
Each such file contains a typed abstract syntax tree (AST), that is produced
during the type checking procedure. This tree contains all available information
about the location and the specific type of each term in the source file.
The AST is partial if type checking was unsuccessful.</p><p>These <span class="c003">.cmt</span> and <span class="c003">.cmti</span> files are typically useful for code inspection tools.</p>
<h2 class="section" id="s:comp-options"><a class="section-anchor" href="#s:comp-options" aria-hidden="true"></a>9.2  Options</h2>
<p>The following command-line options are recognized by <span class="c003">ocamlc</span>.
The options <span class="c003">-pack</span>, <span class="c003">-a</span>, <span class="c003">-c</span> and <span class="c003">-output-obj</span> are mutually exclusive.
</p><dl class="description"><dt class="dt-description">
<span class="c006">-a</span></dt><dd class="dd-description">
Build a library(<span class="c003">.cma</span> file)
with the object files ( <span class="c003">.cmo</span> files)
given on the command line, instead of linking them into an executable file.
The name of the library must be set with the <span class="c003">-o</span> option.<p>If <span class="c003">-custom</span>, <span class="c003">-cclib</span> or <span class="c003">-ccopt</span> options are passed on the command
line, these options are stored in the resulting <span class="c003">.cma</span>library. Then,
linking with this library automatically adds back the <span class="c003">-custom</span>, 
<span class="c003">-cclib</span> and <span class="c003">-ccopt</span> options as if they had been provided on the
command line, unless the <span class="c003">-noautolink</span> option is given.
</p></dd><dt class="dt-description"><span class="c006">-absname</span></dt><dd class="dd-description">
Force error messages to show absolute paths for file names.</dd><dt class="dt-description"><span class="c006">-annot</span></dt><dd class="dd-description">
Deprecated since OCaml 4.11. Please use <span class="c003">-bin-annot</span> instead.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-args</span> <span class="c009">filename</span></span></dt><dd class="dd-description">
Read additional newline-terminated command line arguments from <span class="c009">filename</span>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-args0</span> <span class="c009">filename</span></span></dt><dd class="dd-description">
Read additional null character terminated command line arguments from
<span class="c009">filename</span>.
</dd><dt class="dt-description"><span class="c006">-bin-annot</span></dt><dd class="dd-description">
Dump detailed information about the compilation (types, bindings,
tail-calls, etc) in binary format. The information for file <span class="c009">src</span><span class="c003">.ml</span>
(resp. <span class="c009">src</span><span class="c003">.mli</span>) is put into file <span class="c009">src</span><span class="c003">.cmt</span>
(resp. <span class="c009">src</span><span class="c003">.cmti</span>). In case of a type error, dump
all the information inferred by the type-checker before the error.
The <span class="c003">*.cmt</span> and <span class="c003">*.cmti</span> files produced by <span class="c003">-bin-annot</span> contain
more information and are much more compact than the files produced by
<span class="c003">-annot</span>.
</dd><dt class="dt-description"><span class="c006">-c</span></dt><dd class="dd-description">
Compile only. Suppress the linking phase of the
compilation. Source code files are turned into compiled files, but no
executable file is produced. This option is useful to
compile modules separately.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-cc</span> <span class="c009">ccomp</span></span></dt><dd class="dd-description">
Use <span class="c009">ccomp</span> as the C linker 
when linking in “custom runtime” mode (see the <span class="c003">-custom</span> option)
and as the C compiler for compiling <span class="c003">.c</span> source files.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-cclib</span> <span class="c003">-l</span><span class="c009">libname</span></span></dt><dd class="dd-description">
Pass the <span class="c003">-l</span><span class="c009">libname</span> option to the C linker
when linking in “custom runtime” mode (see the <span class="c003">-custom</span> option).
This causes the given C library to be linked with the program.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-ccopt</span> <span class="c009">option</span></span></dt><dd class="dd-description">
Pass the given option to the C compiler and linker.
When linking in “custom runtime” mode, for instance<span class="c003">-ccopt -L</span><span class="c009">dir</span> causes the C linker to search for C libraries in
directory <span class="c009">dir</span>.(See the <span class="c003">-custom</span> option.)
</dd><dt class="dt-description"><span class="c013"><span class="c003">-color</span> <span class="c009">mode</span></span></dt><dd class="dd-description">
Enable or disable colors in compiler messages (especially warnings and errors).
The following modes are supported:
<dl class="description"><dt class="dt-description">
<span class="c006">auto</span></dt><dd class="dd-description"> use heuristics to enable colors only if the output supports them
(an ANSI-compatible tty terminal);
</dd><dt class="dt-description"><span class="c006">always</span></dt><dd class="dd-description"> enable colors unconditionally;
</dd><dt class="dt-description"><span class="c006">never</span></dt><dd class="dd-description"> disable color output.
</dd></dl>
The default setting is ’auto’, and the current heuristic
checks that the <span class="c003">TERM</span> environment variable exists and is
not empty or <span class="c003">dumb</span>, and that ’isatty(stderr)’ holds.<p>The environment variable <span class="c003">OCAML_COLOR</span> is considered if <span class="c003">-color</span> is not
provided. Its values are auto/always/never as above.
</p></dd><dt class="dt-description"><span class="c013"><span class="c003">-error-style</span> <span class="c009">mode</span></span></dt><dd class="dd-description">
Control the way error messages and warnings are printed.
The following modes are supported:
<dl class="description"><dt class="dt-description">
<span class="c006">short</span></dt><dd class="dd-description"> only print the error and its location;
</dd><dt class="dt-description"><span class="c006">contextual</span></dt><dd class="dd-description"> like <span class="c003">short</span>, but also display the source code snippet
corresponding to the location of the error.
</dd></dl>
The default setting is <span class="c003">contextual</span>.<p>The environment variable <span class="c003">OCAML_ERROR_STYLE</span> is considered if <span class="c003">-error-style</span> is
not provided. Its values are short/contextual as above.
</p></dd><dt class="dt-description"><span class="c006">-compat-32</span></dt><dd class="dd-description">
Check that the generated bytecode executable can run on 32-bit
platforms and signal an error if it cannot. This is useful when
compiling bytecode on a 64-bit machine.
</dd><dt class="dt-description"><span class="c006">-config</span></dt><dd class="dd-description">
Print the version number of <span class="c003">ocamlc</span> and a detailed
summary of its configuration, then exit.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-config-var</span> <span class="c009">var</span></span></dt><dd class="dd-description">
Print the value of a specific configuration variable from the
<span class="c003">-config</span> output, then exit. If the variable does not exist, the exit
code is non-zero. This option is only available since OCaml 4.08,
so script authors should have a fallback for older versions.
</dd><dt class="dt-description"><span class="c006">-custom</span></dt><dd class="dd-description">
Link in “custom runtime” mode. In the default linking mode, the
linker produces bytecode that is intended to be executed with the
shared runtime system, <span class="c003">ocamlrun</span>. In the custom runtime mode, the
linker produces an output file that contains both the runtime system
and the bytecode for the program. The resulting file is larger, but it
can be executed directly, even if the <span class="c003">ocamlrun</span> command is not
installed. Moreover, the “custom runtime” mode enables static
linking of OCaml code with user-defined C functions, as described in
chapter <a href="intfc.html#c%3Aintf-c">20</a>.
<blockquote class="quote"><span class="c007">Unix:</span>  
Never use the <span class="c003">strip</span> command on executables produced by <span class="c003">ocamlc -custom</span>,
this would remove the bytecode part of the executable.
</blockquote>
<blockquote class="quote"><span class="c007">Unix:</span>  
Security warning: never set the “setuid” or “setgid” bits on executables
produced by <span class="c003">ocamlc -custom</span>, this would make them vulnerable to attacks.
</blockquote>
</dd><dt class="dt-description"><span class="c013"><span class="c003">-depend</span> <span class="c009">ocamldep-args</span></span></dt><dd class="dd-description">
Compute dependencies, as the <span class="c003">ocamldep</span> command would do. The remaining
arguments are interpreted as if they were given to the <span class="c003">ocamldep</span> command.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-dllib</span> <span class="c003">-l</span><span class="c009">libname</span></span></dt><dd class="dd-description">
Arrange for the C shared library <span class="c003">dll</span><span class="c009">libname</span><span class="c003">.so</span>
(<span class="c003">dll</span><span class="c009">libname</span><span class="c003">.dll</span> under Windows) to be loaded dynamically
by the run-time system <span class="c003">ocamlrun</span> at program start-up time.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-dllpath</span> <span class="c009">dir</span></span></dt><dd class="dd-description">
Adds the directory <span class="c009">dir</span> to the run-time search path for shared
C libraries. At link-time, shared libraries are searched in the
standard search path (the one corresponding to the <span class="c003">-I</span> option).
The <span class="c003">-dllpath</span> option simply stores <span class="c009">dir</span> in the produced
executable file, where <span class="c003">ocamlrun</span> can find it and use it as
described in section <a href="runtime.html#s%3Aocamlrun-dllpath">11.3</a>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-for-pack</span> <span class="c009">module-path</span></span></dt><dd class="dd-description">
Generate an object file (<span class="c003">.cmo</span>)
that can later be included
as a sub-module (with the given access path) of a compilation unit
constructed with <span class="c003">-pack</span>. For instance,
<span class="c003">ocamlc -for-pack P -c A.ml</span>
will generate <span class="c003">a..cmo</span> that can
later be used with <span class="c003">ocamlc -pack -o P.cmo a.cmo</span>.
Note: you can still pack a module that was compiled without
<span class="c003">-for-pack</span> but in this case exceptions will be printed with the wrong
names.
</dd><dt class="dt-description"><span class="c006">-g</span></dt><dd class="dd-description">
Add debugging information while compiling and linking. This option is
required in order to be able to debug the program with <span class="c003">ocamldebug</span>
(see chapter <a href="debugger.html#c%3Adebugger">17</a>), and to produce stack backtraces when
the program terminates on an uncaught exception (see
section <a href="runtime.html#s%3Aocamlrun-options">11.2</a>).
</dd><dt class="dt-description"><span class="c006">-i</span></dt><dd class="dd-description">
Cause the compiler to print all defined names (with their inferred
types or their definitions) when compiling an implementation (<span class="c003">.ml</span>
file). No compiled files (<span class="c003">.cmo</span> and <span class="c003">.cmi</span> files) are produced.
This can be useful to check the types inferred by the
compiler. Also, since the output follows the syntax of interfaces, it
can help in writing an explicit interface (<span class="c003">.mli</span> file) for a file:
just redirect the standard output of the compiler to a <span class="c003">.mli</span> file,
and edit that file to remove all declarations of unexported names.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-I</span> <span class="c009">directory</span></span></dt><dd class="dd-description">
Add the given directory to the list of directories searched for

compiled interface files (<span class="c003">.cmi</span>), compiled object code files <span class="c003">.cmo</span>,
libraries (<span class="c003">.cma</span>) and C libraries specified with <span class="c003">-cclib -lxxx</span>.

By default, the current directory is searched first, then the standard
library directory. Directories added with <span class="c003">-I</span> are searched after the
current directory, in the order in which they were given on the command line,
but before the standard library directory. See also option <span class="c003">-nostdlib</span>.<p>If the given directory starts with <span class="c003">+</span>, it is taken relative to the
standard library directory. For instance, <span class="c003">-I +unix</span> adds the
subdirectory <span class="c003">unix</span> of the standard library to the search path.</p></dd><dt class="dt-description"><span class="c013"><span class="c003">-impl</span> <span class="c009">filename</span></span></dt><dd class="dd-description">
Compile the file <span class="c009">filename</span> as an implementation file, even if its
extension is not <span class="c003">.ml</span>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-intf</span> <span class="c009">filename</span></span></dt><dd class="dd-description">
Compile the file <span class="c009">filename</span> as an interface file, even if its
extension is not <span class="c003">.mli</span>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-intf-suffix</span> <span class="c009">string</span></span></dt><dd class="dd-description">
Recognize file names ending with <span class="c009">string</span> as interface files
(instead of the default <span class="c003">.mli</span>).
</dd><dt class="dt-description"><span class="c006">-labels</span></dt><dd class="dd-description">
Labels are not ignored in types, labels may be used in applications,
and labelled parameters can be given in any order. This is the default.</dd><dt class="dt-description"><span class="c006">-linkall</span></dt><dd class="dd-description">
Force all modules contained in libraries to be linked in. If this
flag is not given, unreferenced modules are not linked in. When
building a library (option <span class="c003">-a</span>), setting the <span class="c003">-linkall</span> option forces all
subsequent links of programs involving that library to link all the
modules contained in the library. When compiling a module (option
<span class="c003">-c</span>), setting the <span class="c003">-linkall</span> option ensures that this module will
always be linked if it is put in a library and this library is linked.
</dd><dt class="dt-description"><span class="c006">-make-runtime</span></dt><dd class="dd-description">
Build a custom runtime system (in the file specified by option <span class="c003">-o</span>)
incorporating the C object files and libraries given on the command
line. This custom runtime system can be used later to execute
bytecode executables produced with the
<span class="c003">ocamlc -use-runtime</span> <span class="c009">runtime-name</span> option.
See section <a href="intfc.html#ss%3Acustom-runtime">20.1.6</a> for more information.
</dd><dt class="dt-description"><span class="c006">-match-context-rows</span></dt><dd class="dd-description">
Set the number of rows of context used for optimization during
pattern matching compilation. The default value is 32. Lower values
cause faster compilation, but less optimized code. This advanced
option is meant for use in the event that a pattern-match-heavy
program leads to significant increases in compilation time.
</dd><dt class="dt-description"><span class="c006">-no-alias-deps</span></dt><dd class="dd-description">
Do not record dependencies for module aliases. See
section <a href="modulealias.html#s%3Amodule-alias">8.8</a> for more information.
</dd><dt class="dt-description"><span class="c006">-no-app-funct</span></dt><dd class="dd-description">
Deactivates the applicative behaviour of functors. With this option,
each functor application generates new types in its result and
applying the same functor twice to the same argument yields two
incompatible structures.</dd><dt class="dt-description"><span class="c006">-noassert</span></dt><dd class="dd-description">
Do not compile assertion checks. Note that the special form
<span class="c003">assert false</span> is always compiled because it is typed specially.
This flag has no effect when linking already-compiled files.</dd><dt class="dt-description"><span class="c006">-noautolink</span></dt><dd class="dd-description">
When linking <span class="c003">.cma</span>libraries, ignore <span class="c003">-custom</span>, <span class="c003">-cclib</span> and <span class="c003">-ccopt</span>
options potentially contained in the libraries (if these options were
given when building the libraries). This can be useful if a library
contains incorrect specifications of C libraries or C options; in this
case, during linking, set <span class="c003">-noautolink</span> and pass the correct C
libraries and options on the command line.
</dd><dt class="dt-description"><span class="c006">-nolabels</span></dt><dd class="dd-description">
Ignore non-optional labels in types. Labels cannot be used in
applications, and parameter order becomes strict.</dd><dt class="dt-description"><span class="c006">-nostdlib</span></dt><dd class="dd-description">
Do not include the standard library directory in the list of
directories searched for
compiled interface files (<span class="c003">.cmi</span>), compiled object code files
(<span class="c003">.cmo</span>), libraries (<span class="c003">.cma</span>), and C libraries specified with
<span class="c003">-cclib -lxxx</span>. See also option <span class="c003">-I</span>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-o</span> <span class="c009">exec-file</span></span></dt><dd class="dd-description">
Specify the name of the output file produced by the
compiler. The
default output name is <span class="c003">a.out</span> under Unix and <span class="c003">camlprog.exe</span> under
Windows. If the <span class="c003">-a</span> option is given, specify the name of the library
produced. If the <span class="c003">-pack</span> option is given, specify the name of the
packed object file produced. If the <span class="c003">-output-obj</span> option is given,
specify the name of the output file produced.

If the <span class="c003">-c</span> option is given, specify the name of the object
file produced for the <em>next</em> source file that appears on the
command line.
</dd><dt class="dt-description"><span class="c006">-opaque</span></dt><dd class="dd-description">
When the native compiler compiles an implementation, by default it
produces a <span class="c003">.cmx</span> file containing information for cross-module
optimization. It also expects <span class="c003">.cmx</span> files to be present for the
dependencies of the currently compiled source, and uses them for
optimization. Since OCaml 4.03, the compiler will emit a warning if it
is unable to locate the <span class="c003">.cmx</span> file of one of those dependencies.<p>The <span class="c003">-opaque</span> option, available since 4.04, disables cross-module
optimization information for the currently compiled unit. When
compiling <span class="c003">.mli</span> interface, using <span class="c003">-opaque</span> marks the compiled <span class="c003">.cmi</span>
interface so that subsequent compilations of modules that depend on it
will not rely on the corresponding <span class="c003">.cmx</span> file, nor warn if it is
absent. When the native compiler compiles a <span class="c003">.ml</span> implementation,
using <span class="c003">-opaque</span> generates a <span class="c003">.cmx</span> that does not contain any
cross-module optimization information.</p><p>Using this option may degrade the quality of generated code, but it
reduces compilation time, both on clean and incremental
builds. Indeed, with the native compiler, when the implementation of
a compilation unit changes, all the units that depend on it may need
to be recompiled – because the cross-module information may have
changed. If the compilation unit whose implementation changed was
compiled with <span class="c003">-opaque</span>, no such recompilation needs to occur. This
option can thus be used, for example, to get faster edit-compile-test
feedback loops.
</p></dd><dt class="dt-description"><span class="c013"><span class="c003">-open</span> <span class="c009">Module</span></span></dt><dd class="dd-description">
Opens the given module before processing the interface or
implementation files. If several <span class="c003">-open</span> options are given,
they are processed in order, just as if
the statements <span class="c003">open!</span> <span class="c009">Module1</span><span class="c003">;;</span> <span class="c003">...</span> <span class="c003">open!</span> <span class="c009">ModuleN</span><span class="c003">;;</span>
were added at the top of each file.
</dd><dt class="dt-description"><span class="c006">-output-obj</span></dt><dd class="dd-description">
Cause the linker to produce a C object file instead of
a bytecode executable file.
This is useful to wrap OCaml code as a C library,
callable from any C program. See chapter <a href="intfc.html#c%3Aintf-c">20</a>,
section <a href="intfc.html#ss%3Ac-embedded-code">20.7.5</a>. The name of the output object file
must be set with the <span class="c003">-o</span> option.
This option can also be used to produce a C source file (<span class="c003">.c</span> extension)
or a compiled shared/dynamic library (<span class="c003">.so</span> extension, <span class="c003">.dll</span> under Windows).
</dd><dt class="dt-description"><span class="c006">-output-complete-exe</span></dt><dd class="dd-description">
Build a self-contained executable by linking a C object file containing the
bytecode program, the OCaml runtime system and any other static C code given to
<span class="c003">ocamlc</span>. The resulting effect is similar to <span class="c003">-custom</span>, except that the bytecode
is embedded in the C code so it is no longer accessible to tools such as
<span class="c003">ocamldebug</span>. On the other hand, the resulting binary is resistant to <span class="c003">strip</span>.
</dd><dt class="dt-description"><span class="c006">-pack</span></dt><dd class="dd-description">
Build a bytecode object file (<span class="c003">.cmo</span> file) and its associated compiled
interface (<span class="c003">.cmi</span>) that combines the object
files given on the command line, making them appear as sub-modules of
the output <span class="c003">.cmo</span> file. The name of the output <span class="c003">.cmo</span> file must be
given with the <span class="c003">-o</span> option. For instance,
<pre>        ocamlc -pack -o p.cmo a.cmo b.cmo c.cmo
</pre>generates compiled files <span class="c003">p.cmo</span> and <span class="c003">p.cmi</span> describing a compilation
unit having three sub-modules <span class="c003">A</span>, <span class="c003">B</span> and <span class="c003">C</span>, corresponding to the
contents of the object files <span class="c003">a.cmo</span>, <span class="c003">b.cmo</span> and <span class="c003">c.cmo</span>. These
contents can be referenced as <span class="c003">P.A</span>, <span class="c003">P.B</span> and <span class="c003">P.C</span> in the remainder
of the program.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-pp</span> <span class="c009">command</span></span></dt><dd class="dd-description">
Cause the compiler to call the given <span class="c009">command</span> as a preprocessor
for each source file. The output of <span class="c009">command</span> is redirected to
an intermediate file, which is compiled. If there are no compilation
errors, the intermediate file is deleted afterwards.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-ppx</span> <span class="c009">command</span></span></dt><dd class="dd-description">
After parsing, pipe the abstract syntax tree through the preprocessor
<span class="c009">command</span>. The module <span class="c003">Ast_mapper</span>, described in
chapter <a href="parsing.html#c%3Aparsinglib">27</a>:
<a href="compilerlibref/Ast_mapper.html"> <span class="c003">Ast_mapper</span> </a>
,
implements the external interface of a preprocessor.</dd><dt class="dt-description"><span class="c006">-principal</span></dt><dd class="dd-description">
Check information path during type-checking, to make sure that all
types are derived in a principal way. When using labelled arguments
and/or polymorphic methods, this flag is required to ensure future
versions of the compiler will be able to infer types correctly, even
if internal algorithms change.
All programs accepted in <span class="c003">-principal</span> mode are also accepted in the
default mode with equivalent types, but different binary signatures,
and this may slow down type checking; yet it is a good idea to
use it once before publishing source code.</dd><dt class="dt-description"><span class="c006">-rectypes</span></dt><dd class="dd-description">
Allow arbitrary recursive types during type-checking. By default,
only recursive types where the recursion goes through an object type
are supported.Note that once you have created an interface using this
flag, you must use it again for all dependencies.</dd><dt class="dt-description"><span class="c013"><span class="c003">-runtime-variant</span> <span class="c009">suffix</span></span></dt><dd class="dd-description">
Add the <span class="c009">suffix</span> string to the name of the runtime library used by
the program. Currently, only one such suffix is supported: <span class="c003">d</span>, and
only if the OCaml compiler was configured with option
<span class="c003">-with-debug-runtime</span>. This suffix gives the debug version of the
runtime, which is useful for debugging pointer problems in low-level
code such as C stubs.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-stop-after</span> <span class="c009">pass</span></span></dt><dd class="dd-description">
Stop compilation after the given compilation pass. The currently
supported passes are: <span class="c003">parsing</span>, <span class="c003">typing</span>.
</dd><dt class="dt-description"><span class="c006">-safe-string</span></dt><dd class="dd-description">
Enforce the separation between types <span class="c003">string</span> and <span class="c003">bytes</span>,
thereby making strings read-only. This is the default.</dd><dt class="dt-description"><span class="c006">-short-paths</span></dt><dd class="dd-description">
When a type is visible under several module-paths, use the shortest
one when printing the type’s name in inferred interfaces and error and
warning messages. Identifier names starting with an underscore <span class="c003">_</span> or
containing double underscores <span class="c003">__</span> incur a penalty of +10 when computing
their length.</dd><dt class="dt-description"><span class="c006">-strict-sequence</span></dt><dd class="dd-description">
Force the left-hand part of each sequence to have type unit.</dd><dt class="dt-description"><span class="c006">-strict-formats</span></dt><dd class="dd-description">
Reject invalid formats that were accepted in legacy format
implementations. You should use this flag to detect and fix such
invalid formats, as they will be rejected by future OCaml versions.</dd><dt class="dt-description"><span class="c006">-unboxed-types</span></dt><dd class="dd-description">
When a type is unboxable (i.e. a record with a single argument or a
concrete datatype with a single constructor of one argument) it will
be unboxed unless annotated with <span class="c003">[@@ocaml.boxed]</span>.
</dd><dt class="dt-description"><span class="c006">-no-unboxed-types</span></dt><dd class="dd-description">
When a type is unboxable it will be boxed unless annotated with
<span class="c003">[@@ocaml.unboxed]</span>. This is the default.
</dd><dt class="dt-description"><span class="c006">-unsafe</span></dt><dd class="dd-description">
Turn bound checking off for array and string accesses (the <span class="c003">v.(i)</span> and
<span class="c003">s.[i]</span> constructs). Programs compiled with <span class="c003">-unsafe</span> are therefore
slightly faster, but unsafe: anything can happen if the program
accesses an array or string outside of its bounds.
Additionally, turn off the check for zero divisor in integer division
and modulus operations. With <span class="c003">-unsafe</span>, an integer division
(or modulus) by zero can halt the program or continue with an
unspecified result instead of raising a <span class="c003">Division_by_zero</span> exception.
</dd><dt class="dt-description"><span class="c006">-unsafe-string</span></dt><dd class="dd-description">
Identify the types <span class="c003">string</span> and <span class="c003">bytes</span>, thereby making strings writable.
This is intended for compatibility with old source code and should not
be used with new software.</dd><dt class="dt-description"><span class="c013"><span class="c003">-use-runtime</span> <span class="c009">runtime-name</span></span></dt><dd class="dd-description">
Generate a bytecode executable file that can be executed on the custom
runtime system <span class="c009">runtime-name</span>, built earlier with
<span class="c003">ocamlc -make-runtime</span> <span class="c009">runtime-name</span>.
See section <a href="intfc.html#ss%3Acustom-runtime">20.1.6</a> for more information.
</dd><dt class="dt-description"><span class="c006">-v</span></dt><dd class="dd-description">
Print the version number of the compiler and the location of the
standard library directory, then exit.</dd><dt class="dt-description"><span class="c006">-verbose</span></dt><dd class="dd-description">
Print all external commands before they are executed,

in particular invocations of the C compiler and linker in <span class="c003">-custom</span> mode.
Useful to debug C library problems.</dd><dt class="dt-description"><span class="c013"><span class="c003">-version</span> or <span class="c003">-vnum</span></span></dt><dd class="dd-description">
Print the version number of the compiler in short form (e.g. <span class="c003">3.11.0</span>),
then exit.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-w</span> <span class="c009">warning-list</span></span></dt><dd class="dd-description">
Enable, disable, or mark as fatal the warnings specified by the argument
<span class="c009">warning-list</span>.
Each warning can be <em>enabled</em> or <em>disabled</em>, and each warning
can be <em>fatal</em> or <em>non-fatal</em>.
If a warning is disabled, it isn’t displayed and doesn’t affect
compilation in any way (even if it is fatal). If a warning is
enabled, it is displayed normally by the compiler whenever the source
code triggers it. If it is enabled and fatal, the compiler will also
stop with an error after displaying it.<p>The <span class="c009">warning-list</span> argument is a sequence of warning specifiers,
with no separators between them. A warning specifier is one of the
following:</p><dl class="description"><dt class="dt-description">
<span class="c013"><span class="c003">+</span><span class="c009">num</span></span></dt><dd class="dd-description"> Enable warning number <span class="c009">num</span>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-</span><span class="c009">num</span></span></dt><dd class="dd-description"> Disable warning number <span class="c009">num</span>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">@</span><span class="c009">num</span></span></dt><dd class="dd-description"> Enable and mark as fatal warning number <span class="c009">num</span>.
</dd><dt class="dt-description"><span class="c013"><span class="c003">+</span><span class="c009">num1</span>..<span class="c009">num2</span></span></dt><dd class="dd-description"> Enable warnings in the given range.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-</span><span class="c009">num1</span>..<span class="c009">num2</span></span></dt><dd class="dd-description"> Disable warnings in the given range.
</dd><dt class="dt-description"><span class="c013"><span class="c003">@</span><span class="c009">num1</span>..<span class="c009">num2</span></span></dt><dd class="dd-description"> Enable and mark as fatal warnings in
the given range.
</dd><dt class="dt-description"><span class="c013"><span class="c003">+</span><span class="c009">letter</span></span></dt><dd class="dd-description"> Enable the set of warnings corresponding to
<span class="c009">letter</span>. The letter may be uppercase or lowercase.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-</span><span class="c009">letter</span></span></dt><dd class="dd-description"> Disable the set of warnings corresponding to
<span class="c009">letter</span>. The letter may be uppercase or lowercase.
</dd><dt class="dt-description"><span class="c013"><span class="c003">@</span><span class="c009">letter</span></span></dt><dd class="dd-description"> Enable and mark as fatal the set of warnings
corresponding to <span class="c009">letter</span>. The letter may be uppercase or
lowercase.
</dd><dt class="dt-description"><span class="c011">uppercase-letter</span></dt><dd class="dd-description"> Enable the set of warnings corresponding
to <span class="c009">uppercase-letter</span>.
</dd><dt class="dt-description"><span class="c011">lowercase-letter</span></dt><dd class="dd-description"> Disable the set of warnings corresponding
to <span class="c009">lowercase-letter</span>.
</dd></dl><p>Warning numbers and letters which are out of the range of warnings
that are currently defined are ignored. The warnings are as follows.
</p><dl class="description"><dt class="dt-description">
<span class="c013">1</span></dt><dd class="dd-description"> Suspicious-looking start-of-comment mark.
</dd><dt class="dt-description"><span class="c013">2</span></dt><dd class="dd-description"> Suspicious-looking end-of-comment mark.
</dd><dt class="dt-description"><span class="c013">3</span></dt><dd class="dd-description"> Deprecated synonym for the ’deprecated’ alert.
</dd><dt class="dt-description"><span class="c013">4</span></dt><dd class="dd-description"> Fragile pattern matching: matching that will remain complete even
if additional constructors are added to one of the variant types
matched.
</dd><dt class="dt-description"><span class="c013">5</span></dt><dd class="dd-description"> Partially applied function: expression whose result has function
type and is ignored.
</dd><dt class="dt-description"><span class="c013">6</span></dt><dd class="dd-description"> Label omitted in function application.
</dd><dt class="dt-description"><span class="c013">7</span></dt><dd class="dd-description"> Method overridden.
</dd><dt class="dt-description"><span class="c013">8</span></dt><dd class="dd-description"> Partial match: missing cases in pattern-matching.
</dd><dt class="dt-description"><span class="c013">9</span></dt><dd class="dd-description"> Missing fields in a record pattern.
</dd><dt class="dt-description"><span class="c013">10</span></dt><dd class="dd-description"> Expression on the left-hand side of a sequence that doesn’t have type
<span class="c003">unit</span> (and that is not a function, see warning number 5).
</dd><dt class="dt-description"><span class="c013">11</span></dt><dd class="dd-description"> Redundant case in a pattern matching (unused match case).
</dd><dt class="dt-description"><span class="c013">12</span></dt><dd class="dd-description"> Redundant sub-pattern in a pattern-matching.
</dd><dt class="dt-description"><span class="c013">13</span></dt><dd class="dd-description"> Instance variable overridden.
</dd><dt class="dt-description"><span class="c013">14</span></dt><dd class="dd-description"> Illegal backslash escape in a string constant.
</dd><dt class="dt-description"><span class="c013">15</span></dt><dd class="dd-description"> Private method made public implicitly.
</dd><dt class="dt-description"><span class="c013">16</span></dt><dd class="dd-description"> Unerasable optional argument.
</dd><dt class="dt-description"><span class="c013">17</span></dt><dd class="dd-description"> Undeclared virtual method.
</dd><dt class="dt-description"><span class="c013">18</span></dt><dd class="dd-description"> Non-principal type.
</dd><dt class="dt-description"><span class="c013">19</span></dt><dd class="dd-description"> Type without principality.
</dd><dt class="dt-description"><span class="c013">20</span></dt><dd class="dd-description"> Unused function argument.
</dd><dt class="dt-description"><span class="c013">21</span></dt><dd class="dd-description"> Non-returning statement.
</dd><dt class="dt-description"><span class="c013">22</span></dt><dd class="dd-description"> Preprocessor warning.
</dd><dt class="dt-description"><span class="c013">23</span></dt><dd class="dd-description"> Useless record <span class="c003">with</span> clause.
</dd><dt class="dt-description"><span class="c013">24</span></dt><dd class="dd-description"> Bad module name: the source file name is not a valid OCaml module name.
</dd><dt class="dt-description"><span class="c013">25</span></dt><dd class="dd-description"> Deprecated: now part of warning 8.
</dd><dt class="dt-description"><span class="c013">26</span></dt><dd class="dd-description"> Suspicious unused variable: unused variable that is bound
with <span class="c003">let</span> or <span class="c003">as</span>, and doesn’t start with an underscore (<span class="c003">_</span>)
character.
</dd><dt class="dt-description"><span class="c013">27</span></dt><dd class="dd-description"> Innocuous unused variable: unused variable that is not bound with
<span class="c003">let</span> nor <span class="c003">as</span>, and doesn’t start with an underscore (<span class="c003">_</span>)
character.
</dd><dt class="dt-description"><span class="c013">28</span></dt><dd class="dd-description"> Wildcard pattern given as argument to a constant constructor.
</dd><dt class="dt-description"><span class="c013">29</span></dt><dd class="dd-description"> Unescaped end-of-line in a string constant (non-portable code).
</dd><dt class="dt-description"><span class="c013">30</span></dt><dd class="dd-description"> Two labels or constructors of the same name are defined in two
mutually recursive types.
</dd><dt class="dt-description"><span class="c013">31</span></dt><dd class="dd-description"> A module is linked twice in the same executable.
</dd><dt class="dt-description"><span class="c013">32</span></dt><dd class="dd-description"> Unused value declaration.
</dd><dt class="dt-description"><span class="c013">33</span></dt><dd class="dd-description"> Unused open statement.
</dd><dt class="dt-description"><span class="c013">34</span></dt><dd class="dd-description"> Unused type declaration.
</dd><dt class="dt-description"><span class="c013">35</span></dt><dd class="dd-description"> Unused for-loop index.
</dd><dt class="dt-description"><span class="c013">36</span></dt><dd class="dd-description"> Unused ancestor variable.
</dd><dt class="dt-description"><span class="c013">37</span></dt><dd class="dd-description"> Unused constructor.
</dd><dt class="dt-description"><span class="c013">38</span></dt><dd class="dd-description"> Unused extension constructor.
</dd><dt class="dt-description"><span class="c013">39</span></dt><dd class="dd-description"> Unused rec flag.
</dd><dt class="dt-description"><span class="c013">40</span></dt><dd class="dd-description"> Constructor or label name used out of scope.
</dd><dt class="dt-description"><span class="c013">41</span></dt><dd class="dd-description"> Ambiguous constructor or label name.
</dd><dt class="dt-description"><span class="c013">42</span></dt><dd class="dd-description"> Disambiguated constructor or label name (compatibility warning).
</dd><dt class="dt-description"><span class="c013">43</span></dt><dd class="dd-description"> Nonoptional label applied as optional.
</dd><dt class="dt-description"><span class="c013">44</span></dt><dd class="dd-description"> Open statement shadows an already defined identifier.
</dd><dt class="dt-description"><span class="c013">45</span></dt><dd class="dd-description"> Open statement shadows an already defined label or constructor.
</dd><dt class="dt-description"><span class="c013">46</span></dt><dd class="dd-description"> Error in environment variable.
</dd><dt class="dt-description"><span class="c013">47</span></dt><dd class="dd-description"> Illegal attribute payload.
</dd><dt class="dt-description"><span class="c013">48</span></dt><dd class="dd-description"> Implicit elimination of optional arguments.
</dd><dt class="dt-description"><span class="c013">49</span></dt><dd class="dd-description"> Absent cmi file when looking up module alias.
</dd><dt class="dt-description"><span class="c013">50</span></dt><dd class="dd-description"> Unexpected documentation comment.
</dd><dt class="dt-description"><span class="c013">51</span></dt><dd class="dd-description"> Warning on non-tail calls if @tailcall present.
</dd><dt class="dt-description"><span class="c013">52 (see </span><a href="#ss%3Awarn52"><span class="c013">9.5.2</span></a><span class="c013">)</span></dt><dd class="dd-description"> Fragile constant pattern.
</dd><dt class="dt-description"><span class="c013">53</span></dt><dd class="dd-description"> Attribute cannot appear in this context.
</dd><dt class="dt-description"><span class="c013">54</span></dt><dd class="dd-description"> Attribute used more than once on an expression.
</dd><dt class="dt-description"><span class="c013">55</span></dt><dd class="dd-description"> Inlining impossible.
</dd><dt class="dt-description"><span class="c013">56</span></dt><dd class="dd-description"> Unreachable case in a pattern-matching (based on type information).
</dd><dt class="dt-description"><span class="c013">57 (see </span><a href="#ss%3Awarn57"><span class="c013">9.5.3</span></a><span class="c013">)</span></dt><dd class="dd-description"> Ambiguous or-pattern variables under guard.
</dd><dt class="dt-description"><span class="c013">58</span></dt><dd class="dd-description"> Missing cmx file.
</dd><dt class="dt-description"><span class="c013">59</span></dt><dd class="dd-description"> Assignment to non-mutable value.
</dd><dt class="dt-description"><span class="c013">60</span></dt><dd class="dd-description"> Unused module declaration.
</dd><dt class="dt-description"><span class="c013">61</span></dt><dd class="dd-description"> Unboxable type in primitive declaration.
</dd><dt class="dt-description"><span class="c013">62</span></dt><dd class="dd-description"> Type constraint on GADT type declaration.
</dd><dt class="dt-description"><span class="c013">63</span></dt><dd class="dd-description"> Erroneous printed signature.
</dd><dt class="dt-description"><span class="c013">64</span></dt><dd class="dd-description"> -unsafe used with a preprocessor returning a syntax tree.
</dd><dt class="dt-description"><span class="c013">65</span></dt><dd class="dd-description"> Type declaration defining a new ’()’ constructor.
</dd><dt class="dt-description"><span class="c013">66</span></dt><dd class="dd-description"> Unused open! statement.
</dd><dt class="dt-description"><span class="c013">67</span></dt><dd class="dd-description"> Unused functor parameter.
</dd><dt class="dt-description"><span class="c013">A</span></dt><dd class="dd-description"> all warnings
</dd><dt class="dt-description"><span class="c013">C</span></dt><dd class="dd-description"> warnings 1, 2.
</dd><dt class="dt-description"><span class="c013">D</span></dt><dd class="dd-description"> Alias for warning 3.
</dd><dt class="dt-description"><span class="c013">E</span></dt><dd class="dd-description"> Alias for warning 4.
</dd><dt class="dt-description"><span class="c013">F</span></dt><dd class="dd-description"> Alias for warning 5.
</dd><dt class="dt-description"><span class="c013">K</span></dt><dd class="dd-description"> warnings 32, 33, 34, 35, 36, 37, 38, 39.
</dd><dt class="dt-description"><span class="c013">L</span></dt><dd class="dd-description"> Alias for warning 6.
</dd><dt class="dt-description"><span class="c013">M</span></dt><dd class="dd-description"> Alias for warning 7.
</dd><dt class="dt-description"><span class="c013">P</span></dt><dd class="dd-description"> Alias for warning 8.
</dd><dt class="dt-description"><span class="c013">R</span></dt><dd class="dd-description"> Alias for warning 9.
</dd><dt class="dt-description"><span class="c013">S</span></dt><dd class="dd-description"> Alias for warning 10.
</dd><dt class="dt-description"><span class="c013">U</span></dt><dd class="dd-description"> warnings 11, 12.
</dd><dt class="dt-description"><span class="c013">V</span></dt><dd class="dd-description"> Alias for warning 13.
</dd><dt class="dt-description"><span class="c013">X</span></dt><dd class="dd-description"> warnings 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 30.
</dd><dt class="dt-description"><span class="c013">Y</span></dt><dd class="dd-description"> Alias for warning 26.
</dd><dt class="dt-description"><span class="c013">Z</span></dt><dd class="dd-description"> Alias for warning 27.

</dd></dl><p>The default setting is <span class="c003">-w +a-4-6-7-9-27-29-32..42-44-45-48-50-60</span>.
It is displayed by <span class="c003">ocamlc -help</span>.
Note that warnings 5 and 10 are not always triggered, depending on
the internals of the type checker.</p></dd><dt class="dt-description"><span class="c013"><span class="c003">-warn-error</span> <span class="c009">warning-list</span></span></dt><dd class="dd-description">
Mark as fatal the warnings specified in the argument <span class="c009">warning-list</span>.
The compiler will stop with an error when one of these warnings is
emitted. The <span class="c009">warning-list</span> has the same meaning as for
the <span class="c003">-w</span> option: a <span class="c003">+</span> sign (or an uppercase letter) marks the
corresponding warnings as fatal, a <span class="c003">-</span>
sign (or a lowercase letter) turns them back into non-fatal warnings,
and a <span class="c003">@</span> sign both enables and marks as fatal the corresponding
warnings.<p>Note: it is not recommended to use warning sets (i.e. letters) as
arguments to <span class="c003">-warn-error</span>
in production code, because this can break your build when future versions
of OCaml add some new warnings.</p><p>The default setting is <span class="c003">-warn-error -a+31</span> (only warning 31 is fatal).</p></dd><dt class="dt-description"><span class="c006">-warn-help</span></dt><dd class="dd-description">
Show the description of all available warning numbers.</dd><dt class="dt-description"><span class="c006">-where</span></dt><dd class="dd-description">
Print the location of the standard library, then exit.
</dd><dt class="dt-description"><span class="c006">-with-runtime</span></dt><dd class="dd-description">
Include the runtime system in the generated program. This is the default.
</dd><dt class="dt-description"><span class="c006">-without-runtime</span></dt><dd class="dd-description">
The compiler does not include the runtime system (nor a reference to it) in the
generated program; it must be supplied separately.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-</span> <span class="c009">file</span></span></dt><dd class="dd-description">
Process <span class="c009">file</span> as a file name, even if it starts with a dash (<span class="c003">-</span>)
character.
</dd><dt class="dt-description"><span class="c013"><span class="c003">-help</span> or <span class="c003">--help</span></span></dt><dd class="dd-description">
Display a short usage summary and exit.</dd></dl>
<h5 class="paragraph" id="sec290"><a class="section-anchor" href="#sec290" aria-hidden="true"></a>contextual-cli-control</h5>
<p>Contextual control of command-line options</p><p>The compiler command line can be modified “from the outside”
with the following mechanisms. These are experimental
and subject to change. They should be used only for experimental and
development work, not in released packages.</p><dl class="description"><dt class="dt-description">
<span class="c006">OCAMLPARAM</span> (environment variable)</dt><dd class="dd-description">
A set of arguments that will be inserted before or after the arguments from
the command line. Arguments are specified in a comma-separated list
of <span class="c003">name=value</span> pairs. A <span class="c003">_</span> is used to specify the position of
the command line arguments, i.e. <span class="c003">a=x,_,b=y</span> means that <span class="c003">a=x</span> should be
executed before parsing the arguments, and <span class="c003">b=y</span> after. Finally,
an alternative separator can be specified as the
first character of the string, within the set <span class="c003">:|; ,</span>.
</dd><dt class="dt-description"><span class="c006">ocaml_compiler_internal_params</span> (file in the stdlib directory)</dt><dd class="dd-description">
A mapping of file names to lists of arguments that
will be added to the command line (and <span class="c003">OCAMLPARAM</span>) arguments.
</dd><dt class="dt-description"><span class="c006">OCAML_FLEXLINK</span> (environment variable)</dt><dd class="dd-description">
Alternative executable to use on native
Windows for <span class="c003">flexlink</span> instead of the
configured value. Primarily used for bootstrapping.
</dd></dl>
<h2 class="section" id="s:modules-file-system"><a class="section-anchor" href="#s:modules-file-system" aria-hidden="true"></a>9.3  Modules and the file system</h2>
<p>This short section is intended to clarify the relationship between the
names of the modules corresponding to compilation units and the names
of the files that contain their compiled interface and compiled
implementation.</p><p>The compiler always derives the module name by taking the capitalized
base name of the source file (<span class="c003">.ml</span> or <span class="c003">.mli</span> file). That is, it
strips the leading directory name, if any, as well as the <span class="c003">.ml</span> or
<span class="c003">.mli</span> suffix; then, it set the first letter to uppercase, in order to
comply with the requirement that module names must be capitalized.
For instance, compiling the file <span class="c003">mylib/misc.ml</span> provides an
implementation for the module named <span class="c003">Misc</span>. Other compilation units
may refer to components defined in <span class="c003">mylib/misc.ml</span> under the names
<span class="c003">Misc.</span><span class="c009">name</span>; they can also do <span class="c003">open Misc</span>, then use unqualified
names <span class="c009">name</span>.</p><p>The <span class="c003">.cmi</span> and <span class="c003">.cmo</span> files produced by the compiler have the same
base name as the source file. Hence, the compiled files always have
their base name equal (modulo capitalization of the first letter) to
the name of the module they describe (for <span class="c003">.cmi</span> files) or implement
(for <span class="c003">.cmo</span> files).</p><p>When the compiler encounters a reference to a free module identifier
<span class="c003">Mod</span>, it looks in the search path for a file named <span class="c003">Mod.cmi</span> or <span class="c003">mod.cmi</span>
and loads the compiled interface
contained in that file. As a consequence, renaming <span class="c003">.cmi</span> files is not
advised: the name of a <span class="c003">.cmi</span> file must always correspond to the name
of the compilation unit it implements. It is admissible to move them
to another directory, if their base name is preserved, and the correct
<span class="c003">-I</span> options are given to the compiler. The compiler will flag an
error if it loads a <span class="c003">.cmi</span> file that has been renamed.</p><p>Compiled bytecode files (<span class="c003">.cmo</span> files), on the other hand, can be
freely renamed once created. That’s because the linker never attempts
to find by itself the <span class="c003">.cmo</span> file that implements a module with a
given name: it relies instead on the user providing the list of <span class="c003">.cmo</span>
files by hand.</p>
<h2 class="section" id="s:comp-errors"><a class="section-anchor" href="#s:comp-errors" aria-hidden="true"></a>9.4  Common errors</h2>
<p>This section describes and explains the most frequently encountered
error messages.</p><dl class="description"><dt class="dt-description"><span class="c013">Cannot find file <span class="c009">filename</span></span></dt><dd class="dd-description">
The named file could not be found in the current directory, nor in the
directories of the search path. The <span class="c009">filename</span> is either a
compiled interface file (<span class="c003">.cmi</span> file), or a compiled bytecode file
(<span class="c003">.cmo</span> file). If <span class="c009">filename</span> has the format <span class="c009">mod</span><span class="c003">.cmi</span>, this
means you are trying to compile a file that references identifiers
from module <span class="c009">mod</span>, but you have not yet compiled an interface for
module <span class="c009">mod</span>. Fix: compile <span class="c009">mod</span><span class="c003">.mli</span> or <span class="c009">mod</span><span class="c003">.ml</span>
first, to create the compiled interface <span class="c009">mod</span><span class="c003">.cmi</span>.<p>If <span class="c009">filename</span> has the format <span class="c009">mod</span><span class="c003">.cmo</span>, this
means you are trying to link a bytecode object file that does not
exist yet. Fix: compile <span class="c009">mod</span><span class="c003">.ml</span> first.</p><p>If your program spans several directories, this error can also appear
because you haven’t specified the directories to look into. Fix: add
the correct <span class="c003">-I</span> options to the command line.</p></dd><dt class="dt-description"><span class="c013">Corrupted compiled interface <span class="c009">filename</span></span></dt><dd class="dd-description">
The compiler produces this error when it tries to read a compiled
interface file (<span class="c003">.cmi</span> file) that has the wrong structure. This means
something went wrong when this <span class="c003">.cmi</span> file was written: the disk was
full, the compiler was interrupted in the middle of the file creation,
and so on. This error can also appear if a <span class="c003">.cmi</span> file is modified after
its creation by the compiler. Fix: remove the corrupted <span class="c003">.cmi</span> file,
and rebuild it.</dd><dt class="dt-description"><span class="c013">This expression has type </span><span class="c009">t</span><sub>1</sub><span class="c013">, but is used with type </span><span class="c009">t</span><sub>2</sub></dt><dd class="dd-description">
This is by far the most common type error in programs. Type <span class="c009">t</span><sub>1</sub> is
the type inferred for the expression (the part of the program that is
displayed in the error message), by looking at the expression itself.
Type <span class="c009">t</span><sub>2</sub> is the type expected by the context of the expression; it
is deduced by looking at how the value of this expression is used in
the rest of the program. If the two types <span class="c009">t</span><sub>1</sub> and <span class="c009">t</span><sub>2</sub> are not
compatible, then the error above is produced.<p>In some cases, it is hard to understand why the two types <span class="c009">t</span><sub>1</sub> and
<span class="c009">t</span><sub>2</sub> are incompatible. For instance, the compiler can report that
“expression of type <span class="c003">foo</span> cannot be used with type <span class="c003">foo</span>”, and it
really seems that the two types <span class="c003">foo</span> are compatible. This is not
always true. Two type constructors can have the same name, but
actually represent different types. This can happen if a type
constructor is redefined. Example:
</p><pre>        type foo = A | B
        let f = function A -&gt; 0 | B -&gt; 1
        type foo = C | D
        f C
</pre><p>This result in the error message “expression <span class="c003">C</span> of type <span class="c003">foo</span> cannot
be used with type <span class="c003">foo</span>”.</p></dd><dt class="dt-description"><span class="c013">The type of this expression, <span class="c009">t</span>, contains type variables
that cannot be generalized</span></dt><dd class="dd-description">
Type variables (<span class="c003">'a</span>, <span class="c003">'b</span>, …) in a type <span class="c009">t</span> can be in either
of two states: generalized (which means that the type <span class="c009">t</span> is valid
for all possible instantiations of the variables) and not generalized
(which means that the type <span class="c009">t</span> is valid only for one instantiation
of the variables). In a <span class="c003">let</span> binding <span class="c003">let </span><span class="c009">name</span><span class="c003"> = </span><span class="c009">expr</span>,
the type-checker normally generalizes as many type variables as
possible in the type of <span class="c009">expr</span>. However, this leads to unsoundness
(a well-typed program can crash) in conjunction with polymorphic
mutable data structures. To avoid this, generalization is performed at
<span class="c003">let</span> bindings only if the bound expression <span class="c009">expr</span> belongs to the
class of “syntactic values”, which includes constants, identifiers,
functions, tuples of syntactic values, etc. In all other cases (for
instance, <span class="c009">expr</span> is a function application), a polymorphic mutable
could have been created and generalization is therefore turned off for
all variables occurring in contravariant or non-variant branches of the
type. For instance, if the type of a non-value is <span class="c003">'a list</span> the
variable is generalizable (<span class="c003">list</span> is a covariant type constructor),
but not in <span class="c003">'a list -&gt; 'a list</span> (the left branch of <span class="c003">-&gt;</span> is
contravariant) or <span class="c003">'a ref</span> (<span class="c003">ref</span> is non-variant).<p>Non-generalized type variables in a type cause no difficulties inside
a given structure or compilation unit (the contents of a <span class="c003">.ml</span> file,
or an interactive session), but they cannot be allowed inside
signatures nor in compiled interfaces (<span class="c003">.cmi</span> file), because they
could be used inconsistently later. Therefore, the compiler
flags an error when a structure or compilation unit defines a value
<span class="c009">name</span> whose type contains non-generalized type variables. There
are two ways to fix this error:
</p><ul class="itemize"><li class="li-itemize">
Add a type constraint or a <span class="c003">.mli</span> file to give a monomorphic
type (without type variables) to <span class="c009">name</span>. For instance, instead of
writing
<pre>    let sort_int_list = List.sort Stdlib.compare
    (* inferred type 'a list -&gt; 'a list, with 'a not generalized *)
</pre>write
<pre>    let sort_int_list = (List.sort Stdlib.compare : int list -&gt; int list);;
</pre></li><li class="li-itemize">If you really need <span class="c009">name</span> to have a polymorphic type, turn
its defining expression into a function by adding an extra parameter.
For instance, instead of writing
<pre>    let map_length = List.map Array.length
    (* inferred type 'a array list -&gt; int list, with 'a not generalized *)
</pre>write
<pre>    let map_length lv = List.map Array.length lv
</pre></li></ul></dd><dt class="dt-description"><span class="c013">Reference to undefined global <span class="c009">mod</span></span></dt><dd class="dd-description">
This error appears when trying to link an incomplete or incorrectly
ordered set of files. Either you have forgotten to provide an
implementation for the compilation unit named <span class="c009">mod</span> on the command line
(typically, the file named <span class="c009">mod</span><span class="c003">.cmo</span>, or a library containing
that file). Fix: add the missing <span class="c003">.ml</span> or <span class="c003">.cmo</span> file to the command
line. Or, you have provided an implementation for the module named
<span class="c009">mod</span>, but it comes too late on the command line: the
implementation of <span class="c009">mod</span> must come before all bytecode object files
that reference <span class="c009">mod</span>. Fix: change the order of <span class="c003">.ml</span> and <span class="c003">.cmo</span>
files on the command line.<p>Of course, you will always encounter this error if you have mutually
recursive functions across modules. That is, function <span class="c003">Mod1.f</span> calls
function <span class="c003">Mod2.g</span>, and function <span class="c003">Mod2.g</span> calls function <span class="c003">Mod1.f</span>.
In this case, no matter what permutations you perform on the command
line, the program will be rejected at link-time. Fixes:
</p><ul class="itemize"><li class="li-itemize">
Put <span class="c003">f</span> and <span class="c003">g</span> in the same module.
</li><li class="li-itemize">Parameterize one function by the other.
That is, instead of having
<pre>mod1.ml:    let f x = ... Mod2.g ...
mod2.ml:    let g y = ... Mod1.f ...
</pre>define
<pre>mod1.ml:    let f g x = ... g ...
mod2.ml:    let rec g y = ... Mod1.f g ...
</pre>and link <span class="c003">mod1.cmo</span> before <span class="c003">mod2.cmo</span>.
</li><li class="li-itemize">Use a reference to hold one of the two functions, as in :
<pre>mod1.ml:    let forward_g =
                ref((fun x -&gt; failwith "forward_g") : &lt;type&gt;)
            let f x = ... !forward_g ...
mod2.ml:    let g y = ... Mod1.f ...
            let _ = Mod1.forward_g := g
</pre></li></ul></dd><dt class="dt-description"><span class="c013">The external function <span class="c009">f</span> is not available</span></dt><dd class="dd-description">
This error appears when trying to link code that calls external
functions written in C. As explained in
chapter <a href="intfc.html#c%3Aintf-c">20</a>, such code must be linked with C libraries that
implement the required <span class="c009">f</span> C function. If the C libraries in
question are not shared libraries (DLLs), the code must be linked in
“custom runtime” mode. Fix: add the required C libraries to the
command line, and possibly the <span class="c003">-custom</span> option.</dd></dl>
<h2 class="section" id="s:comp-warnings"><a class="section-anchor" href="#s:comp-warnings" aria-hidden="true"></a>9.5  Warning reference</h2>
<p>This section describes and explains in detail some warnings:</p>
<h3 class="subsection" id="ss:warn9"><a class="section-anchor" href="#ss:warn9" aria-hidden="true"></a>9.5.1  Warning 9: missing fields in a record pattern</h3>
<p>When pattern matching on records, it can be useful to match only few
fields of a record. Eliding fields can be done either implicitly
or explicitly by ending the record pattern with <span class="c003">; _</span>.
However, implicit field elision is at odd with pattern matching
exhaustiveness checks.
Enabling warning 9 prioritizes exhaustiveness checks over the
convenience of implicit field elision and will warn on implicit
field elision in record patterns. In particular, this warning can
help to spot exhaustive record pattern that may need to be updated
after the addition of new fields to a record type.</p><pre>type 'a point = {x : 'a; y : 'a}
let dx { x } = x (* implicit field elision: trigger warning 9 *)
let dy { y; _ } = y (* explicit field elision: do not trigger warning 9 *)
</pre>
<h3 class="subsection" id="ss:warn52"><a class="section-anchor" href="#ss:warn52" aria-hidden="true"></a>9.5.2  Warning 52: fragile constant pattern</h3>
<p>Some constructors, such as the exception constructors <span class="c003">Failure</span> and
<span class="c003">Invalid_argument</span>, take as parameter a <span class="c003">string</span> value holding
a text message intended for the user.</p><p>These text messages are usually not stable over time: call sites
building these constructors may refine the message in a future
version to make it more explicit, etc. Therefore, it is dangerous to
match over the precise value of the message. For example, until
OCaml 4.02, <span class="c003">Array.iter2</span> would raise the exception
</p><pre>  Invalid_argument "arrays must have the same length"
</pre><p> Since 4.03 it raises the more helpful message
</p><pre>  Invalid_argument "Array.iter2: arrays must have the same length"
</pre><p> but this means that any code of the form
</p><pre>  try ...
  with Invalid_argument "arrays must have the same length" -&gt; ...
</pre><p> is now broken and may suffer from uncaught exceptions.</p><p>Warning 52 is there to prevent users from writing such fragile code
in the first place. It does not occur on every matching on a literal
string, but only in the case in which library authors expressed
their intent to possibly change the constructor parameter value in
the future, by using the attribute <span class="c003">ocaml.warn_on_literal_pattern</span>
(see the manual section on builtin attributes in
<a href="attributes.html#ss%3Abuiltin-attributes">8.12.1</a>):
</p><pre>  type t =
    | Foo of string [@ocaml.warn_on_literal_pattern]
    | Bar of string

  let no_warning = function
    | Bar "specific value" -&gt; 0
    | _ -&gt; 1

  let warning = function
    | Foo "specific value" -&gt; 0
    | _ -&gt; 1

&gt;    | Foo "specific value" -&gt; 0
&gt;          ^^^^^^^^^^^^^^^^
&gt; Warning 52: Code should not depend on the actual values of
&gt; this constructor's arguments. They are only for information
&gt; and may change in future versions. (See manual section 8.5)
</pre><p>
In particular, all built-in exceptions with a string argument have
this attribute set: <span class="c003">Invalid_argument</span>, <span class="c003">Failure</span>, <span class="c003">Sys_error</span> will
all raise this warning if you match for a specific string argument.</p><p>Additionally, built-in exceptions with a structured argument that
includes a string also have the attribute set: <span class="c003">Assert_failure</span> and
<span class="c003">Match_failure</span> will raise the warning for a pattern that uses a
literal string to match the first element of their tuple argument.</p><p>If your code raises this warning, you should <em>not</em> change the
way you test for the specific string to avoid the warning (for
example using a string equality inside the right-hand-side instead
of a literal pattern), as your code would remain fragile. You should
instead enlarge the scope of the pattern by matching on all possible
values.</p><pre>
let warning = function
  | Foo _ -&gt; 0
  | _ -&gt; 1
</pre><p>
This may require some care: if the scrutinee may return several
different cases of the same pattern, or raise distinct instances of
the same exception, you may need to modify your code to separate
those several cases.</p><p>For example,
</p><pre>try (int_of_string count_str, bool_of_string choice_str) with
  | Failure "int_of_string" -&gt; (0, true)
  | Failure "bool_of_string" -&gt; (-1, false)
</pre><p> should be rewritten into more atomic tests. For example,
using the <span class="c003">exception</span> patterns documented in Section <a href="patterns.html#sss%3Aexception-match">7.6</a>,
one can write:
</p><pre>match int_of_string count_str with
  | exception (Failure _) -&gt; (0, true)
  | count -&gt;
    begin match bool_of_string choice_str with
    | exception (Failure _) -&gt; (-1, false)
    | choice -&gt; (count, choice)
    end
</pre><p>
The only case where that transformation is not possible is if a given
function call may raise distinct exceptions with the same constructor
but different string values. In this case, you will have to check for
specific string values. This is dangerous API design and it should be
discouraged: it’s better to define more precise exception constructors
than store useful information in strings.</p>
<h3 class="subsection" id="ss:warn57"><a class="section-anchor" href="#ss:warn57" aria-hidden="true"></a>9.5.3  Warning 57: Ambiguous or-pattern variables under guard</h3>
<p>The semantics of or-patterns in OCaml is specified with
a left-to-right bias: a value <span class="c009">v</span> matches the pattern <span class="c009">p</span> <span class="c003">|</span> <span class="c009">q</span>
if it matches <span class="c009">p</span> or <span class="c009">q</span>, but if it matches both,
the environment captured by the match is the environment captured by
<span class="c009">p</span>, never the one captured by <span class="c009">q</span>.</p><p>While this property is generally intuitive, there is at least one specific
case where a different semantics might be expected.
Consider a pattern followed by a when-guard:
<span class="c003">|</span> <span class="c009">p</span> <span class="c003">when</span> <span class="c009">g</span> <span class="c003">-&gt;</span> <span class="c009">e</span>, for example:
</p><pre>     | ((Const x, _) | (_, Const x)) when is_neutral x -&gt; branch
</pre><p> The semantics is clear:
match the scrutinee against the pattern, if it matches, test the guard,
and if the guard passes, take the branch.
In particular, consider the input <span class="c003">(Const</span> <span class="c009">a</span><span class="c003">, Const</span> <span class="c009">b</span><span class="c003">)</span>, where
<span class="c009">a</span> fails the test <span class="c003">is_neutral</span> <span class="c009">a</span>, while <span class="c009">b</span> passes the test
<span class="c003">is_neutral</span> <span class="c009">b</span>. With the left-to-right semantics, the clause above is
<em>not</em> taken by its input: matching <span class="c003">(Const</span> <span class="c009">a</span><span class="c003">, Const</span> <span class="c009">b</span><span class="c003">)</span>
against the or-pattern succeeds in the left branch, it returns the
environment <span class="c009">x</span> <span class="c003">-&gt;</span> <span class="c009">a</span>, and then the guard
<span class="c003">is_neutral</span> <span class="c009">a</span> is tested and fails, the branch is not taken.</p><p>However, another semantics may be considered more natural here:
any pair that has one side passing the test will take the branch. With this
semantics the previous code fragment would be equivalent to
</p><pre>     | (Const x, _) when is_neutral x -&gt; branch
     | (_, Const x) when is_neutral x -&gt; branch
</pre><p> This is <em>not</em> the semantics adopted by OCaml.</p><p>Warning 57 is dedicated to these confusing cases where the
specified left-to-right semantics is not equivalent to a non-deterministic
semantics (any branch can be taken) relatively to a specific guard.
More precisely, it warns when guard uses “ambiguous” variables, that are bound
to different parts of the scrutinees by different sides of a or-pattern.

</p>
<hr>
<a href="extn.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="toplevel.html"><img src="next_motif.svg" alt="Next"></a>
</body>
</html>