7663cd70615a421437acb927481da8d0b9fe90ed
[ghc-hetmet.git] / ghc / docs / users_guide / using.sgml
1 <Chapter id="using-GHC">
2 <Title>Using GHC
3 </Title>
4
5 <Para>
6 <IndexTerm><Primary>GHC, using</Primary></IndexTerm>
7 <IndexTerm><Primary>using GHC</Primary></IndexTerm>
8 GHC is a command-line compiler: in order to compile a Haskell program,
9 GHC must be invoked on the source file(s) by typing a command to the
10 shell.  The steps involved in compiling a program can be automated
11 using the <Command>make</Command> tool (this is especially useful if the program
12 consists of multiple source files which depend on each other).  This
13 section describes how to use GHC from the command-line.
14 </Para>
15
16 <Sect1 id="command-line-structure">
17 <Title>Overall command-line structure
18 </Title>
19
20 <Para>
21 <IndexTerm><Primary>structure, command-line</Primary></IndexTerm>
22 <IndexTerm><Primary>command-line structure</Primary></IndexTerm>
23 </Para>
24
25 <Para>
26 An invocation of GHC takes the following form:
27 </Para>
28
29 <Para>
30
31 <Screen>
32 ghc [argument...]
33 </Screen>
34
35 </Para>
36
37 <Para>
38 Command-line arguments are either options or file names.
39 </Para>
40
41 <Para>
42 Command-line options begin with <Literal>-</Literal>.  They may <Emphasis>not</Emphasis> be
43 grouped: <Option>-vO</Option> is different from <Option>-v -O</Option>.  Options need not
44 precede filenames: e.g., <Command>ghc *.o -o foo</Command>.  All options are
45 processed and then applied to all files; you cannot, for example, invoke
46 <Command>ghc -c -O1 Foo.hs -O2 Bar.hs</Command> to apply different optimisation
47 levels to the files <Filename>Foo.hs</Filename> and <Filename>Bar.hs</Filename>.  For conflicting
48 options, e.g., <Option>-c -S</Option>, we reserve the right to do anything we
49 want.  (Usually, the last one applies.)
50 </Para>
51
52 </Sect1>
53
54 <Sect1 id="file-suffixes">
55 <Title>Meaningful file suffixes
56 </Title>
57
58 <Para>
59 <IndexTerm><Primary>suffixes, file</Primary></IndexTerm>
60 <IndexTerm><Primary>file suffixes for GHC</Primary></IndexTerm>
61 </Para>
62
63 <Para>
64 File names with &ldquo;meaningful&rdquo; suffixes (e.g., <Filename>.lhs</Filename> or <Filename>.o</Filename>)
65 cause the &ldquo;right thing&rdquo; to happen to those files.
66 </Para>
67
68 <Para>
69 <VariableList>
70
71 <VarListEntry>
72 <Term><Filename>.lhs</Filename>:</Term>
73 <ListItem>
74 <Para>
75 <IndexTerm><Primary>lhs suffix</Primary></IndexTerm>
76 A &ldquo;literate Haskell&rdquo; module.
77 </Para>
78 </ListItem>
79 </VarListEntry>
80 <VarListEntry>
81 <Term><Filename>.hs</Filename>:</Term>
82 <ListItem>
83 <Para>
84 A not-so-literate Haskell module.
85 </Para>
86 </ListItem>
87 </VarListEntry>
88 <VarListEntry>
89 <Term><Filename>.hi</Filename>:</Term>
90 <ListItem>
91 <Para>
92 A Haskell interface file, probably compiler-generated.
93 </Para>
94 </ListItem>
95 </VarListEntry>
96 <VarListEntry>
97 <Term><Filename>.hc</Filename>:</Term>
98 <ListItem>
99 <Para>
100 Intermediate C file produced by the Haskell compiler.
101 </Para>
102 </ListItem>
103 </VarListEntry>
104 <VarListEntry>
105 <Term><Filename>.c</Filename>:</Term>
106 <ListItem>
107 <Para>
108 A C&nbsp;file not produced by the Haskell compiler.
109 </Para>
110 </ListItem>
111 </VarListEntry>
112 <VarListEntry>
113 <Term><Filename>.s</Filename>:</Term>
114 <ListItem>
115 <Para>
116 An assembly-language source file, usually
117 produced by the compiler.
118 </Para>
119 </ListItem>
120 </VarListEntry>
121 <VarListEntry>
122 <Term><Filename>.o</Filename>:</Term>
123 <ListItem>
124 <Para>
125 An object file, produced by an assembler.
126 </Para>
127 </ListItem>
128 </VarListEntry>
129 </VariableList>
130 </Para>
131
132 <Para>
133 Files with other suffixes (or without suffixes) are passed straight
134 to the linker.
135 </Para>
136
137 </Sect1>
138
139 <Sect1 id="options-help">
140 <Title>Help and verbosity options
141 </Title>
142
143 <Para>
144 <IndexTerm><Primary>help options (GHC)</Primary></IndexTerm>
145 <IndexTerm><Primary>verbose option (GHC)</Primary></IndexTerm>
146 </Para>
147
148 <Para>
149 A good option to start with is the <Option>-help</Option> (or <Option>-?</Option>) option.
150 <IndexTerm><Primary>-help option</Primary></IndexTerm>
151 <IndexTerm><Primary>-? option</Primary></IndexTerm>
152 GHC spews a long message to standard output and then exits.
153 </Para>
154
155 <Para>
156 The <Option>-v</Option><IndexTerm><Primary>-v option</Primary></IndexTerm> option makes GHC <Emphasis>verbose</Emphasis>: it
157 reports its version number and shows (on stderr) exactly how it invokes each
158 phase of the compilation system.  Moreover, it passes
159 the <Option>-v</Option> flag to most phases; each reports
160 its version number (and possibly some other information).
161 </Para>
162
163 <Para>
164 Please, oh please, use the <Option>-v</Option> option when reporting bugs!
165 Knowing that you ran the right bits in the right order is always the
166 first thing we want to verify.
167 </Para>
168
169 <Para>
170 If you're just interested in the compiler version number, the
171 <Option>--version</Option><IndexTerm><Primary>--version option</Primary></IndexTerm> option prints out a
172 one-line string containing the requested info.
173 </Para>
174
175 </Sect1>
176
177 <Sect1 id="options-order">
178 <Title>Running the right phases in the right order
179 </Title>
180
181 <Para>
182 <IndexTerm><Primary>order of passes in GHC</Primary></IndexTerm>
183 <IndexTerm><Primary>pass ordering in GHC</Primary></IndexTerm>
184 The basic task of the <Command>ghc</Command> driver is to run each input file
185 through the right phases (compiling, linking, etc.).
186 </Para>
187
188 <Para>
189 The first phase to run is determined by the input-file suffix, and the
190 last phase is determined by a flag.  If no relevant flag is present,
191 then go all the way through linking.  This table summarises:
192 </Para>
193
194 <Para>
195 <InformalTable>
196 <TGroup Cols="4">
197 <ColSpec Align="Left">
198 <ColSpec Align="Left">
199 <ColSpec Align="Left">
200 <ColSpec Align="Left">
201 <TBody>
202
203 <Row>
204 <Entry>Phase of the compilation system</Entry>
205 <Entry>Suffix saying &ldquo;start here&rdquo;</Entry>
206 <Entry>Flag saying &ldquo;stop after&rdquo;</Entry>
207 <Entry>(suffix of) output file</Entry>
208 </Row>
209
210 <Row>
211 <Entry>
212 literate pre-processor </Entry>
213 <Entry> .lhs </Entry>
214 <Entry> - </Entry>
215 <Entry> - </Entry>
216 </Row>
217 <Row>
218 <Entry>
219 C pre-processor (opt.) </Entry>
220 <Entry> - </Entry>
221 <Entry> - </Entry>
222 <Entry> - </Entry>
223 </Row>
224 <Row>
225 <Entry>
226 Haskell compiler </Entry>
227 <Entry> .hs </Entry>
228 <Entry> -C, -S </Entry>
229 <Entry> .hc, .s </Entry>
230 </Row>
231 <Row>
232 <Entry>
233 C compiler (opt.) </Entry>
234 <Entry> .hc or .c </Entry>
235 <Entry> -S </Entry>
236 <Entry> .s </Entry>
237 </Row>
238 <Row>
239 <Entry>
240 assembler </Entry>
241 <Entry> .s </Entry>
242 <Entry> -c </Entry>
243 <Entry> .o </Entry>
244 </Row>
245 <Row>
246 <Entry>
247 linker </Entry>
248 <Entry> other </Entry>
249 <Entry> - </Entry>
250 <Entry> a.out </Entry>
251 </Row>
252 </TBody>
253 </TGroup>
254 </InformalTable>
255
256 <IndexTerm><Primary>-C option</Primary></IndexTerm>
257 <IndexTerm><Primary>-S option</Primary></IndexTerm>
258 <IndexTerm><Primary>-c option</Primary></IndexTerm>
259 </Para>
260
261 <Para>
262 Thus, a common invocation would be: <Command>ghc -c Foo.hs</Command>
263 </Para>
264
265 <Para>
266 Note: What the Haskell compiler proper produces depends on whether a
267 native-code generator is used (producing assembly language) or not
268 (producing C).
269 </Para>
270
271 <Para>
272 The option <Option>-cpp</Option><IndexTerm><Primary>-cpp option</Primary></IndexTerm> must be given for the C
273 pre-processor phase to be run, that is, the pre-processor will be run
274 over your Haskell source file before continuing.
275 </Para>
276
277 <Para>
278 The option <Option>-E</Option><IndexTerm><Primary>-E option</Primary></IndexTerm> runs just the pre-processing
279 passes of the compiler, outputting the result on stdout before
280 stopping. If used in conjunction with -cpp, the output is the
281 code blocks of the original (literal) source after having put it
282 through the grinder that is the C pre-processor. Sans <Option>-cpp</Option>, the
283 output is the de-litted version of the original source.
284 </Para>
285
286 <Para>
287 The option <Option>-optcpp-E</Option><IndexTerm><Primary>-optcpp-E option</Primary></IndexTerm> runs just the
288 pre-processing stage of the C-compiling phase, sending the result to
289 stdout.  (For debugging or obfuscation contests, usually.)
290 </Para>
291
292 </Sect1>
293
294 <Sect1 id="options-output">
295 <Title>Re-directing the compilation output(s)
296 </Title>
297
298 <Para>
299 <IndexTerm><Primary>output-directing options</Primary></IndexTerm>
300 </Para>
301
302 <Para>
303 GHC's compiled output normally goes into a <Filename>.hc</Filename>, <Filename>.o</Filename>, etc., file,
304 depending on the last-run compilation phase.  The option <Option>-o
305 foo</Option><IndexTerm><Primary>-o option</Primary></IndexTerm> re-directs the output of that last-run
306 phase to file <Filename>foo</Filename>.
307 </Para>
308
309 <Para>
310 Note: this &ldquo;feature&rdquo; can be counterintuitive:
311 <Command>ghc -C -o foo.o foo.hs</Command> will put the intermediate C code in the
312 file <Filename>foo.o</Filename>, name notwithstanding!
313 </Para>
314
315 <Para>
316 EXOTICA: But the <Option>-o</Option> option isn't of much use if you have
317 <Emphasis>several</Emphasis> input files&hellip; Non-interface output files are
318 normally put in the same directory as their corresponding input file
319 came from.  You may specify that they be put in another directory
320 using the <Option>-odir &lt;dir&gt;</Option><IndexTerm><Primary>-odir &lt;dir&gt; option</Primary></IndexTerm> (the
321 &ldquo;Oh, dear&rdquo; option).  For example:
322 </Para>
323
324 <Para>
325
326 <Screen>
327 % ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch`
328 </Screen>
329
330 </Para>
331
332 <Para>
333 The output files, <Filename>Foo.o</Filename>, <Filename>Bar.o</Filename>, and <Filename>Bumble.o</Filename> would be
334 put into a subdirectory named after the architecture of the executing
335 machine (<Filename>sun4</Filename>, <Filename>mips</Filename>, etc).  The directory must already
336 exist; it won't be created.
337 </Para>
338
339 <Para>
340 Note that the <Option>-odir</Option> option does <Emphasis>not</Emphasis> affect where the
341 interface files are put.  In the above example, they would still be
342 put in <Filename>parse/Foo.hi</Filename>, <Filename>parse/Bar.hi</Filename>, and <Filename>gurgle/Bumble.hi</Filename>.
343 </Para>
344
345 <Para>
346 MORE EXOTICA: The <Option>-osuf &lt;suffix&gt;</Option><IndexTerm><Primary>-osuf &lt;suffix&gt;
347 option</Primary></IndexTerm> will change the <Filename>.o</Filename> file suffix for object files to
348 whatever you specify.  (We use this in compiling the prelude.).
349 Similarly, the <Option>-hisuf &lt;suffix&gt;</Option><IndexTerm><Primary>-hisuf &lt;suffix&gt;
350 option</Primary></IndexTerm> will change the <Filename>.hi</Filename> file suffix for non-system
351 interface files (see <XRef LinkEnd="hi-options">).
352 </Para>
353
354 <Para>
355 The <Option>-hisuf</Option>/<Option>-osuf</Option> game is useful if you want to compile a program
356 with both GHC and HBC (say) in the same directory.  Let HBC use the
357 standard <Filename>.hi</Filename>/<Filename>.o</Filename> suffixes; add <Option>-hisuf g&lowbar;hi -osuf g&lowbar;o</Option> to your
358 <Command>make</Command> rule for GHC compiling&hellip;
359 </Para>
360
361     <sect2 id="keeping-intermediates">
362       <title>Keeping Intermediate Files</title>
363       <indexterm><primary>intermediate files, saving</primary>
364       </indexterm>
365       <indexterm><primary><literal>.hc</literal> files, saving</primary>
366       </indexterm>
367       <indexterm><primary><literal>.s</literal> files, saving</primary>
368       </indexterm>
369
370       <para>The following options are useful for keeping certain
371       intermediate files around, when normally GHC would throw these
372       away after compilation:</para>
373
374       <variablelist>
375         <varlistentry>
376           <term><literal>-keep-hc-files</literal></term>
377           <indexterm>
378             <primary><literal>-keep-hc-files</literal></primary>
379           </indexterm>
380           <listitem>
381             <para>Keep intermediate <literal>.hc</literal> files when
382             doing <literal>.hs</literal>-to-<literal>.o</literal>
383             compilations via C (NOTE: <literal>.hc</literal> files
384             aren't generated when using the native code generator, you
385             may need to use <literal>-fvia-C</literal> to force them
386             to be produced).</para>
387           </listitem>
388         </varlistentry>
389
390         <varlistentry>
391           <term><literal>-keep-s-files</literal></term>
392           <indexterm>
393             <primary><literal>-keep-s-files</literal></primary>
394           </indexterm>
395           <listitem>
396             <para>Keep intermediate <literal>.s</literal> files.</para>
397           </listitem>
398         </varlistentry>
399
400         <varlistentry>
401           <term><literal>-keep-raw-s-files</literal></term>
402           <indexterm>
403             <primary><literal>-keep-raw-s-files</literal></primary>
404           </indexterm>
405           <listitem>
406             <para>Keep intermediate <literal>.raw-s</literal> files.
407             These are the direct output from the C compiler, before
408             GHC does &ldquo;assembly mangling&rdquo; to produce the
409             <literal>.s</literal> file.  Again, these are not produced
410             when using the native code generator.</para>
411           </listitem>
412         </varlistentry>
413
414         <varlistentry>
415           <term><literal>-keep-tmp-files</literal></term>
416           <indexterm>
417             <primary><literal>-keep-tmp-files</literal></primary>
418           </indexterm>
419           <indexterm>
420             <primary>temporary files</primary>
421             <secondary>keeping</secondary>
422           </indexterm>
423           <listitem>
424             <para>Instructs the GHC driver not to delete any of its
425             temporary files, which it normally keeps in
426             <literal>/tmp</literal> (or possibly elsewhere; see <xref
427             linkend="temp-files">).  Running GHC with
428             <literal>-v</literal> will show you what temporary files
429             were generated along the way.</para>
430           </listitem>
431         </varlistentry>
432       </variablelist>
433     </sect2>
434
435 <Sect2 id="saving-ghc-stderr">
436 <Title>Saving GHC's standard error output
437 </Title>
438
439 <Para>
440 <IndexTerm><Primary>standard error, saving</Primary></IndexTerm>
441 </Para>
442
443 <Para>
444 Sometimes, you may cause GHC to be rather chatty on standard error;
445 with <Option>-v</Option>, for example.  You can instruct GHC to <Emphasis>append</Emphasis> this
446 output to a particular log file with a <Option>-odump &lt;blah&gt;</Option><IndexTerm><Primary>-odump
447 &lt;blah&gt; option</Primary></IndexTerm> option.
448 </Para>
449
450 </Sect2>
451
452 <Sect2 id="temp-files">
453 <Title>Redirecting temporary files
454 </Title>
455
456       <indexterm>
457         <primary>temporary files</primary>
458         <secondary>redirecting</secondary>
459       </indexterm>
460
461 <Para>
462 If you have trouble because of running out of space in
463 <Filename>/tmp</Filename> (or wherever your installation thinks
464 temporary files should go), you may use the <Option>-tmpdir
465 &lt;dir&gt;</Option><IndexTerm><Primary>-tmpdir &lt;dir&gt;
466 option</Primary></IndexTerm> option to specify an alternate directory.
467 For example, <Option>-tmpdir .</Option> says to put temporary files in
468 the current working directory.
469 </Para>
470
471 <Para>
472 Alternatively, use your <Constant>TMPDIR</Constant> environment
473 variable.<IndexTerm><Primary>TMPDIR environment
474 variable</Primary></IndexTerm> Set it to the name of the directory
475 where temporary files should be put.  GCC and other programs will
476 honour the <Constant>TMPDIR</Constant> variable as well.
477 </Para>
478
479 <Para>
480 Even better idea: Set the <Constant>TMPDIR</Constant> variable when building GHC, and
481 never worry about <Constant>TMPDIR</Constant> again. (see the build documentation).
482 </Para>
483
484 </Sect2>
485
486 </Sect1>
487
488 <Sect1 id="options-sanity">
489 <Title>Warnings and sanity-checking
490 </Title>
491
492 <Para>
493 <IndexTerm><Primary>sanity-checking options</Primary></IndexTerm>
494 <IndexTerm><Primary>warnings</Primary></IndexTerm>
495 GHC has a number of options that select which types of non-fatal error
496 messages, otherwise known as warnings, can be generated during
497 compilation.  By default, you get a standard set of warnings which are
498 generally likely to indicate bugs in your program.  These are:
499 <Option>-fwarn-overlpapping-patterns</Option>, <Option>-fwarn-duplicate-exports</Option>, and
500 <Option>-fwarn-missing-methods</Option>.  The following flags are simple ways to
501 select standard &ldquo;packages&rdquo; of warnings:
502 </Para>
503
504 <Para>
505 <VariableList>
506
507 <VarListEntry>
508 <Term><Option>-Wnot</Option>:</Term>
509 <ListItem>
510 <Para>
511 <IndexTerm><Primary>-Wnot option</Primary></IndexTerm>
512 Turns off all warnings, including the standard ones.
513 </Para>
514 </ListItem>
515 </VarListEntry>
516
517 <VarListEntry>
518 <Term><Option>-w</Option>:</Term>
519 <ListItem>
520 <Para>
521 <IndexTerm><Primary>-w option</Primary></IndexTerm>
522 Synonym for <Option>-Wnot</Option>.
523 </Para>
524 </ListItem>
525 </VarListEntry>
526
527 <VarListEntry>
528 <Term><Option>-W</Option>:</Term>
529 <ListItem>
530 <Para>
531 <IndexTerm><Primary>-W option</Primary></IndexTerm>
532 Provides the standard warnings plus <Option>-fwarn-incomplete-patterns</Option>,
533 <Option>-fwarn-unused-imports</Option> and <Option>-fwarn-unused-binds</Option>.
534 </Para>
535 </ListItem>
536 </VarListEntry>
537
538 <VarListEntry>
539 <Term><Option>-Wall</Option>:</Term>
540 <ListItem>
541 <Para>
542 <IndexTerm><Primary>-Wall option</Primary></IndexTerm>
543 Turns on all warning options.
544 </Para>
545 </ListItem>
546 </VarListEntry>
547
548 </VariableList>
549 </Para>
550
551 <Para>
552 The full set of warning options is described below.  To turn off any
553 warning, simply give the corresponding <Option>-fno-warn-...</Option> option on
554 the command line.
555 </Para>
556
557 <Para>
558 <VariableList>
559
560 <VarListEntry>
561 <Term><Option>-fwarn-name-shadowing</Option>:</Term>
562 <ListItem>
563 <Para>
564 <IndexTerm><Primary>-fwarn-name-shadowing option</Primary></IndexTerm>
565 <IndexTerm><Primary>shadowing, warning</Primary></IndexTerm>This option causes a warning to be emitted whenever an inner-scope
566 value has the same name as an outer-scope value, i.e. the inner value
567 shadows the outer one.  This can catch typographical errors that turn
568 into hard-to-find bugs, e.g., in the inadvertent cyclic definition
569 <Literal>let x = ... x ... in</Literal>.
570 </Para>
571
572 <Para>
573 Consequently, this option does <Emphasis>not</Emphasis> allow cyclic recursive
574 definitions.
575 </Para>
576 </ListItem>
577 </VarListEntry>
578
579 <VarListEntry>
580 <Term><Option>-fwarn-overlapping-patterns</Option>:</Term>
581 <ListItem>
582 <Para>
583 <IndexTerm><Primary>-fwarn-overlapping-patterns option</Primary></IndexTerm>
584 <IndexTerm><Primary>overlapping patterns, warning</Primary></IndexTerm>
585 <IndexTerm><Primary>patterns, overlapping</Primary></IndexTerm>
586 By default, the compiler will warn you if a set of patterns are
587 overlapping, i.e.,
588 </Para>
589
590 <Para>
591 <ProgramListing>
592 f :: String -&#62; Int
593 f []     = 0
594 f (_:xs) = 1
595 f "2"    = 2
596 </ProgramListing>
597 </Para>
598
599 <Para>
600 where the last pattern match in <Function>f</Function> won't ever be reached, as the
601 second pattern overlaps it. More often than not, redundant patterns
602 is a programmer mistake/error, so this option is enabled by default.
603 </Para>
604 </ListItem>
605 </VarListEntry>
606
607 <VarListEntry>
608 <Term><Option>-fwarn-incomplete-patterns</Option>:</Term>
609 <ListItem>
610 <Para>
611 <IndexTerm><Primary>-fwarn-incomplete-patterns option</Primary></IndexTerm>
612 <IndexTerm><Primary>incomplete patterns, warning</Primary></IndexTerm>
613 <IndexTerm><Primary>patterns, incomplete</Primary></IndexTerm>
614 Similarly for incomplete patterns, the function <Function>g</Function> below will fail
615 when applied to non-empty lists, so the compiler will emit a warning
616 about this when <Option>-fwarn-incomplete-patterns</Option> is enabled.
617 </Para>
618
619 <Para>
620 <ProgramListing>
621 g [] = 2
622 </ProgramListing>
623 </Para>
624
625 <Para>
626 This option isn't enabled be default because it can be a bit noisy,
627 and it doesn't always indicate a bug in the program.  However, it's
628 generally considered good practice to cover all the cases in your
629 functions.
630 </Para>
631 </ListItem>
632 </VarListEntry>
633
634 <VarListEntry>
635 <Term><Option>-fwarn-missing-methods</Option>:</Term>
636 <ListItem>
637 <Para>
638 <IndexTerm><Primary>-fwarn-missing-methods option</Primary></IndexTerm>
639 <IndexTerm><Primary>missing methods, warning</Primary></IndexTerm>
640 <IndexTerm><Primary>methods, missing</Primary></IndexTerm>
641 This option is on by default, and warns you whenever an instance
642 declaration is missing one or more methods, and the corresponding
643 class declaration has no default declaration for them.
644 </Para>
645 </ListItem>
646 </VarListEntry>
647
648 <VarListEntry>
649 <Term><Option>-fwarn-missing-fields</Option>:</Term>
650 <ListItem>
651 <Para>
652 <IndexTerm><Primary>-fwarn-missing-fields option</Primary></IndexTerm>
653 <IndexTerm><Primary>missing fields, warning</Primary></IndexTerm>
654 <IndexTerm><Primary>fields, missing</Primary></IndexTerm>
655 This option is on by default, and warns you whenever the construction
656 of a labelled field constructor isn't complete, missing initializers
657 for one or more fields. While not an error (the missing fields are
658 initialised with bottoms), it is often an indication of a programmer
659 error.
660 </Para>
661 </ListItem>
662 </VarListEntry>
663
664 <VarListEntry>
665 <Term><Option>-fwarn-unused-imports</Option>:</Term>
666 <ListItem>
667 <Para>
668 <IndexTerm><Primary>-fwarn-unused-imports option</Primary></IndexTerm>
669 <IndexTerm><Primary>unused imports, warning</Primary></IndexTerm>
670 <IndexTerm><Primary>imports, unused</Primary></IndexTerm>
671 Report any objects that are explicitly imported but never used.
672 </Para>
673 </ListItem>
674 </VarListEntry>
675
676 <VarListEntry>
677 <Term><Option>-fwarn-unused-binds</Option>:</Term>
678 <ListItem>
679 <Para>
680 <IndexTerm><Primary>-fwarn-unused-binds option</Primary></IndexTerm>
681 <IndexTerm><Primary>unused binds, warning</Primary></IndexTerm>
682 <IndexTerm><Primary>binds, unused</Primary></IndexTerm>
683 Report any function definitions (and local bindings) which are unused.
684 For top-level functions, the warning is only given if the binding is
685 not exported.
686 </Para>
687 </ListItem>
688 </VarListEntry>
689 <VarListEntry>
690 <Term><Option>-fwarn-unused-matches</Option>:</Term>
691 <ListItem>
692 <Para>
693 <IndexTerm><Primary>-fwarn-unused-matches option</Primary></IndexTerm>
694 <IndexTerm><Primary>unused matches, warning</Primary></IndexTerm>
695 <IndexTerm><Primary>matches, unused</Primary></IndexTerm>
696 Report all unused variables which arise from pattern matches,
697 including patterns consisting of a single variable.  For instance <Literal>f x
698 y = []</Literal> would report <VarName>x</VarName> and <VarName>y</VarName> as unused.  To eliminate the warning,
699 all unused variables can be replaced with wildcards.
700 </Para>
701 </ListItem>
702 </VarListEntry>
703
704 <VarListEntry>
705 <Term><Option>-fwarn-duplicate-exports</Option>:</Term>
706 <ListItem>
707 <Para>
708 <IndexTerm><Primary>-fwarn-duplicate-exports option</Primary></IndexTerm>
709 <IndexTerm><Primary>duplicate exports, warning</Primary></IndexTerm>
710 <IndexTerm><Primary>export lists, duplicates</Primary></IndexTerm>
711 Have the compiler warn about duplicate entries in export lists. This
712 is useful information if you maintain large export lists, and want to
713 avoid the continued export of a definition after you've deleted (one)
714 mention of it in the export list.
715 </Para>
716
717 <Para>
718 This option is on by default.
719 </Para>
720 </ListItem>
721 </VarListEntry>
722
723 <VarListEntry>
724 <Term><Option>-fwarn-type-defaults</Option>:</Term>
725 <ListItem>
726 <Para>
727 <IndexTerm><Primary>-fwarn-type-defaults option</Primary></IndexTerm>
728 <IndexTerm><Primary>defaulting mechanism, warning</Primary></IndexTerm>
729 Have the compiler warn/inform you where in your source the Haskell
730 defaulting mechanism for numeric types kicks in. This is useful
731 information when converting code from a context that assumed one
732 default into one with another, e.g., the `default default' for Haskell
733 1.4 caused the otherwise unconstrained value <Constant>1</Constant> to be given
734 the type <Literal>Int</Literal>, whereas Haskell 98 defaults it to
735 <Literal>Integer</Literal>.  This may lead to differences in performance and
736 behaviour, hence the usefulness of being non-silent about this.
737 </Para>
738
739 <Para>
740 This warning is off by default.
741 </Para>
742 </ListItem>
743 </VarListEntry>
744
745 <VarListEntry>
746 <Term><Option>-fwarn-missing-signatures</Option>:</Term>
747 <ListItem>
748 <Para>
749 <IndexTerm><Primary>-fwarn-missing-signatures option</Primary></IndexTerm>
750 <IndexTerm><Primary>type signatures, missing</Primary></IndexTerm>
751 If you would like GHC to check that every top-level function/value has
752 a type signature, use the <Option>-fwarn-missing-signatures</Option> option.  This
753 option is off by default.
754 </Para>
755 </ListItem>
756 </VarListEntry>
757 </VariableList>
758 </Para>
759
760 <Para>
761 If you're feeling really paranoid, the <Option>-dcore-lint</Option>
762 option<IndexTerm><Primary>-dcore-lint option</Primary></IndexTerm> is a good choice.  It turns on
763 heavyweight intra-pass sanity-checking within GHC.  (It checks GHC's
764 sanity, not yours.)
765 </Para>
766
767 </Sect1>
768
769 <Sect1 id="separate-compilation">
770 <Title>Separate compilation
771 </Title>
772
773 <Para>
774 <IndexTerm><Primary>separate compilation</Primary></IndexTerm>
775 <IndexTerm><Primary>recompilation checker</Primary></IndexTerm>
776 <IndexTerm><Primary>make and recompilation</Primary></IndexTerm>
777 This section describes how GHC supports separate compilation.
778 </Para>
779
780 <Sect2 id="hi-files">
781 <Title>Interface files
782 </Title>
783
784 <Para>
785 <IndexTerm><Primary>interface files</Primary></IndexTerm>
786 <IndexTerm><Primary>.hi files</Primary></IndexTerm>
787 </Para>
788
789 <Para>
790 When GHC compiles a source file <Filename>F</Filename> which contains a module <Literal>A</Literal>, say,
791 it generates an object <Filename>F.o</Filename>, <Emphasis>and</Emphasis> a companion <Emphasis>interface
792 file</Emphasis> <Filename>A.hi</Filename>.  The interface file is not intended for human
793 consumption, as you'll see if you take a look at one.  It's merely
794 there to help the compiler compile other modules in the same program.
795 </Para>
796
797 <Para>
798 NOTE: Having the name of the interface file follow the module name and
799 not the file name, means that working with tools such as <Command>make</Command>
800 become harder. <Command>make</Command> implicitly assumes that any output files
801 produced by processing a translation unit will have file names that
802 can be derived from the file name of the translation unit.  For
803 instance, pattern rules becomes unusable.  For this reason, we
804 recommend you stick to using the same file name as the module name.
805 </Para>
806
807 <Para>
808 The interface file for <Literal>A</Literal> contains information needed by the compiler
809 when it compiles any module <Literal>B</Literal> that imports <Literal>A</Literal>, whether directly or
810 indirectly.  When compiling <Literal>B</Literal>, GHC will read <Filename>A.hi</Filename> to find the
811 details that it needs to know about things defined in <Literal>A</Literal>.
812 </Para>
813
814 <Para>
815 Furthermore, when compiling module <Literal>C</Literal> which imports <Literal>B</Literal>, GHC may
816 decide that it needs to know something about <Literal>A</Literal>&mdash;for example, <Literal>B</Literal>
817 might export a function that involves a type defined in <Literal>A</Literal>.  In this
818 case, GHC will go and read <Command>A.hi</Command> even though <Literal>C</Literal> does not explicitly
819 import <Literal>A</Literal> at all.
820 </Para>
821
822 <Para>
823 The interface file may contain all sorts of things that aren't
824 explicitly exported from <Literal>A</Literal> by the programmer.  For example, even
825 though a data type is exported abstractly, <Filename>A.hi</Filename> will contain the
826 full data type definition.  For small function definitions, <Filename>A.hi</Filename>
827 will contain the complete definition of the function.  For bigger
828 functions, <Filename>A.hi</Filename> will contain strictness information about the
829 function.  And so on.  GHC puts much more information into <Filename>.hi</Filename> files
830 when optimisation is turned on with the <Option>-O</Option> flag.  Without <Option>-O</Option> it
831 puts in just the minimum; with <Option>-O</Option> it lobs in a whole pile of stuff.
832 <IndexTerm><Primary>optimsation, effect on .hi files</Primary></IndexTerm>
833 </Para>
834
835 <Para>
836 <Filename>A.hi</Filename> should really be thought of as a compiler-readable version of
837 <Filename>A.o</Filename>.  If you use a <Filename>.hi</Filename> file that wasn't generated by the same
838 compilation run that generates the <Filename>.o</Filename> file the compiler may assume
839 all sorts of incorrect things about <Literal>A</Literal>, resulting in core dumps and
840 other unpleasant happenings.
841 </Para>
842
843 </Sect2>
844
845 <Sect2 id="options-finding-imports">
846 <Title>Finding interface files
847 </Title>
848
849 <Para>
850 <IndexTerm><Primary>interface files, finding them</Primary></IndexTerm>
851 <IndexTerm><Primary>finding interface files</Primary></IndexTerm>
852 </Para>
853
854 <Para>
855 In your program, you import a module <Literal>Foo</Literal> by saying
856 <Literal>import Foo</Literal>.  GHC goes looking for an interface file, <Filename>Foo.hi</Filename>.
857 It has a builtin list of directories (notably including <Filename>.</Filename>) where
858 it looks.
859 </Para>
860
861 <Para>
862 <VariableList>
863
864 <VarListEntry>
865 <Term><Option>-i&lt;dirs&gt;</Option></Term>
866 <ListItem>
867 <Para>
868 <IndexTerm><Primary>-i&lt;dirs&gt; option</Primary></IndexTerm>This flag
869 prepends a colon-separated list of <Filename>dirs</Filename> to the &ldquo;import
870 directories&rdquo; list.
871 See also <XRef LinkEnd="recomp"> for the significance of using
872 relative and absolute pathnames in the <Option>-i</Option> list.
873 </Para>
874 </ListItem>
875 </VarListEntry>
876
877 <VarListEntry>
878 <Term><Option>-i</Option></Term>
879 <ListItem>
880 <Para>
881 resets the &ldquo;import directories&rdquo; list back to nothing.
882 </Para>
883 </ListItem>
884 </VarListEntry>
885
886 <VarListEntry>
887 <Term><Option>-fno-implicit-prelude</Option></Term>
888 <ListItem>
889 <Para>
890 <IndexTerm><Primary>-fno-implicit-prelude option</Primary></IndexTerm>
891 GHC normally imports <Filename>Prelude.hi</Filename> files for you.  If you'd rather it
892 didn't, then give it a <Option>-fno-implicit-prelude</Option> option.  You are
893 unlikely to get very far without a Prelude, but, hey, it's a free
894 country.
895 </Para>
896 </ListItem>
897 </VarListEntry>
898
899 <VarListEntry>
900 <Term><Option>-I&lt;dir&gt;</Option></Term>
901 <ListItem>
902 <Para>
903 <IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
904 Once a Haskell module has been compiled to C (<Filename>.hc</Filename> file), you may
905 wish to specify where GHC tells the C compiler to look for <Filename>.h</Filename> files.
906 (Or, if you are using the <Option>-cpp</Option> option<IndexTerm><Primary>-cpp option</Primary></IndexTerm>, where
907 it tells the C pre-processor to look&hellip;)  For this purpose, use a <Option>-I</Option>
908 option in the usual C-ish way.
909 </Para>
910 </ListItem>
911 </VarListEntry>
912
913 </VariableList>
914 </Para>
915
916 </Sect2>
917
918 <Sect2 id="hi-options">
919 <Title>Other options related to interface files
920 </Title>
921
922 <Para>
923 <IndexTerm><Primary>interface files, options</Primary></IndexTerm>
924 The interface output may be directed to another file
925 <Filename>bar2/Wurble.iface</Filename> with the option <Option>-ohi bar2/Wurble.iface</Option><IndexTerm><Primary>-ohi
926 &lt;file&gt; option</Primary></IndexTerm> (not recommended).
927 </Para>
928
929 <Para>
930 To avoid generating an interface file at all, use a <Option>-nohi</Option>
931 option.<IndexTerm><Primary>-nohi option</Primary></IndexTerm>
932 </Para>
933
934 <Para>
935 The compiler does not overwrite an existing <Filename>.hi</Filename> interface file if
936 the new one is byte-for-byte the same as the old one; this is friendly
937 to <Command>make</Command>.  When an interface does change, it is often enlightening to
938 be informed.  The <Option>-hi-diffs</Option><IndexTerm><Primary>-hi-diffs option</Primary></IndexTerm> option will
939 make GHC run <Command>diff</Command> on the old and new <Filename>.hi</Filename> files. You can also
940 record the difference in the interface file itself, the
941 <Option>-keep-hi-diffs</Option><IndexTerm><Primary>-keep-hi-diffs</Primary></IndexTerm> option takes care of that.
942 </Para>
943
944 <Para>
945 The <Filename>.hi</Filename> files from GHC contain &ldquo;usage&rdquo; information which changes
946 often and uninterestingly.  If you really want to see these changes
947 reported, you need to use the
948 <Option>-hi-diffs-with-usages</Option><IndexTerm><Primary>-hi-diffs-with-usages option</Primary></IndexTerm>
949 option.
950 </Para>
951
952 <Para>
953 Interface files are normally jammed full of compiler-produced
954 <Emphasis>pragmas</Emphasis>, which record arities, strictness info, etc.  If you
955 think these pragmas are messing you up (or you are doing some kind of
956 weird experiment), you can tell GHC to ignore them with the
957 <Option>-fignore-interface-pragmas</Option><IndexTerm><Primary>-fignore-interface-pragmas
958 option</Primary></IndexTerm> option.
959 </Para>
960
961 <Para>
962 When compiling without optimisations on, the compiler is extra-careful
963 about not slurping in data constructors and instance declarations that
964 it will not need. If you believe it is getting it wrong and not
965 importing stuff which you think it should, this optimisation can be
966 turned off with <Option>-fno-prune-tydecls</Option> and <Option>-fno-prune-instdecls</Option>.
967 <IndexTerm><Primary>-fno-prune-tydecls option</Primary></IndexTerm><IndexTerm><Primary>-fno-prune-instdecls
968 option</Primary></IndexTerm>
969 </Para>
970
971 <Para>
972 See also <XRef LinkEnd="options-linker">, which describes how the linker finds standard
973 Haskell libraries.
974 </Para>
975
976 </Sect2>
977
978 <Sect2 id="recomp">
979 <Title>The recompilation checker
980 </Title>
981
982 <IndexTerm><Primary>recompilation checker</Primary></IndexTerm>
983
984 <Para>
985 <variablelist>
986 <VarListEntry>
987 <Term><Option>-recomp</Option></Term>
988 <IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
989 <ListItem>
990 <Para>
991 (On by default) Turn on recompilation checking.  This will stop
992 compilation early, leaving an existing <filename>.o</filename> file in
993 place, if it can be determined that the module does not need to be
994 recompiled.
995 </Para>
996 </ListItem>
997 </VarListEntry>
998 <VarListEntry>
999 <Term><Option>-no-recomp</Option></Term>
1000 <IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
1001 <ListItem>
1002 <Para>
1003 Turn off recompilation checking.
1004 </Para>
1005 </ListItem>
1006 </VarListEntry>
1007 </VariableList>
1008 </Para>
1009
1010 <Para>
1011 In the olden days, GHC compared the newly-generated
1012 <Filename>.hi</Filename> file with the previous version; if they were
1013 identical, it left the old one alone and didn't change its
1014 modification date.  In consequence, importers of a module with an
1015 unchanged output <Filename>.hi</Filename> file were not recompiled.
1016 </Para>
1017
1018 <Para>
1019 This doesn't work any more.  In our earlier example, module
1020 <Literal>C</Literal> does not import module <Literal>A</Literal>
1021 directly, yet changes to <Filename>A.hi</Filename> should force a
1022 recompilation of <Literal>C</Literal>.  And some changes to
1023 <Literal>A</Literal> (changing the definition of a function that
1024 appears in an inlining of a function exported by <Literal>B</Literal>,
1025 say) may conceivably not change <Filename>B.hi</Filename> one jot.  So
1026 now&hellip;
1027 </Para>
1028
1029 <Para>
1030 GHC keeps a version number on each interface file, and on each type
1031 signature within the interface file.  It also keeps in every interface
1032 file a list of the version numbers of everything it used when it last
1033 compiled the file.  If the source file's modification date is earlier
1034 than the <Filename>.o</Filename> file's date (i.e. the source hasn't
1035 changed since the file was last compiled), and the
1036 <option>-recomp</option> is given on the command line, GHC will be
1037 clever.  It compares the version numbers on the things it needs this
1038 time with the version numbers on the things it needed last time
1039 (gleaned from the interface file of the module being compiled); if
1040 they are all the same it stops compiling rather early in the process
1041 saying &ldquo;Compilation IS NOT required&rdquo;.  What a beautiful
1042 sight!
1043 </Para>
1044
1045 <Para>
1046 Patrick Sansom had a workshop paper about how all this is done (though
1047 the details have changed quite a bit). <ULink URL="mailto:sansom@dcs.gla.ac.uk">Ask him</ULink> if you want a copy.
1048 </Para>
1049
1050 </Sect2>
1051
1052
1053 <Sect2 id="using-make">
1054 <Title>Using <Command>make</Command>
1055 </Title>
1056
1057 <Para>
1058 <IndexTerm><Primary><literal>make</literal></Primary></IndexTerm>
1059 </Para>
1060
1061 <Para>
1062 It is reasonably straightforward to set up a <Filename>Makefile</Filename> to use with GHC, assuming you name your source files the same as your modules.
1063 Thus:
1064 </Para>
1065
1066 <Para>
1067
1068 <ProgramListing>
1069 HC      = ghc
1070 HC_OPTS = -cpp $(EXTRA_HC_OPTS)
1071
1072 SRCS = Main.lhs Foo.lhs Bar.lhs
1073 OBJS = Main.o   Foo.o   Bar.o
1074
1075 .SUFFIXES : .o .hs .hi .lhs .hc .s
1076
1077 cool_pgm : $(OBJS)
1078         rm $@
1079         $(HC) -o $@ $(HC_OPTS) $(OBJS)
1080
1081 # Standard suffix rules
1082 .o.hi:
1083         @:
1084
1085 .lhs.o:
1086         $(HC) -c $&#60; $(HC_OPTS)
1087
1088 .hs.o:
1089         $(HC) -c $&#60; $(HC_OPTS)
1090
1091 # Inter-module dependencies
1092 Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
1093 Main.o Main.hc Main.s : Foo.hi Baz.hi   # Main imports Foo and Baz
1094 </ProgramListing>
1095
1096 </Para>
1097
1098 <Para>
1099 (Sophisticated <Command>make</Command> variants may achieve some of the above more
1100 elegantly.  Notably, <Command>gmake</Command>'s pattern rules let you write the more
1101 comprehensible:
1102 </Para>
1103
1104 <Para>
1105
1106 <ProgramListing>
1107 %.o : %.lhs
1108         $(HC) -c $&#60; $(HC_OPTS)
1109 </ProgramListing>
1110
1111 </Para>
1112
1113 <Para>
1114 What we've shown should work with any <Command>make</Command>.)
1115 </Para>
1116
1117 <Para>
1118 Note the cheesy <Literal>.o.hi</Literal> rule: It records the dependency of the
1119 interface (<Filename>.hi</Filename>) file on the source.  The rule says a <Filename>.hi</Filename> file can
1120 be made from a <Filename>.o</Filename> file by doing&hellip;nothing.  Which is true.
1121 </Para>
1122
1123 <Para>
1124 Note the inter-module dependencies at the end of the Makefile, which
1125 take the form
1126 </Para>
1127
1128 <Para>
1129
1130 <ProgramListing>
1131 Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
1132 </ProgramListing>
1133
1134 </Para>
1135
1136 <Para>
1137 They tell <Command>make</Command> that if any of <Literal>Foo.o</Literal>, <Literal>Foo.hc</Literal> or <Literal>Foo.s</Literal> have an
1138 earlier modification date than <Literal>Baz.hi</Literal>, then the out-of-date file
1139 must be brought up to date.  To bring it up to date, <Literal>make</Literal> looks for
1140 a rule to do so; one of the preceding suffix rules does the job
1141 nicely.
1142 </Para>
1143
1144     </sect2>
1145
1146     <sect2 id="sec-makefile-dependencies">
1147       <title>Dependency generation</title>
1148       <indexterm><primary>dependencies in Makefiles</primary></indexterm>
1149       <indexterm><primary>Makefile dependencies</primary></indexterm>
1150
1151       <para>Putting inter-dependencies of the form <Literal>Foo.o :
1152       Bar.hi</Literal> into your <Filename>Makefile</Filename> by hand
1153       is rather error-prone.  Don't worry, GHC has support for
1154       automatically generating the required dependencies.  Add the
1155       following to your <Filename>Makefile</Filename>:</para>
1156
1157 <ProgramListing>
1158 depend :
1159         ghc -M $(HC_OPTS) $(SRCS)
1160 </ProgramListing>
1161
1162       <para>Now, before you start compiling, and any time you change
1163       the <Literal>imports</Literal> in your program, do <Command>make
1164       depend</Command> before you do <Command>make
1165       cool&lowbar;pgm</Command>.  <Command>ghc -M</Command> will append
1166       the needed dependencies to your
1167       <Filename>Makefile</Filename>.</Para>
1168
1169       <para>In general, if module <Literal>A</Literal> contains the
1170       line
1171
1172 <programlisting>
1173 import B ...blah...
1174 </programlisting>
1175
1176        then <command>ghc -M</command> will generate a dependency
1177        line of the form:
1178
1179 <programlisting>
1180 A.o : B.hi
1181 </programlisting>
1182
1183        If module <literal>A</literal> contains the line 
1184
1185 <programlisting>
1186 import {-# SOURCE #-} B ...blah...
1187 </programlisting>
1188
1189        then <command>ghc -M</command> will generate a dependency
1190        line of the form:
1191
1192 <programlisting>
1193 A.o : B.hi-boot
1194 </programlisting>
1195
1196        (See <xref linkend="hi-files"> for details of interface files.)
1197        If <literal>A</literal> imports multiple modules, then there
1198        will be multiple lines with <filename>A.o</filename> as the
1199        target.</para>
1200
1201       <para>By default, <Command>ghc -M</Command> generates all the
1202       dependencies, and then concatenates them onto the end of
1203       <Filename>makefile</Filename> (or <Filename>Makefile</Filename>
1204       if <Filename>makefile</Filename> doesn't exist) bracketed by the
1205       lines "<Literal>&num; DO NOT DELETE: Beginning of Haskell
1206       dependencies</Literal>" and "<Literal>&num; DO NOT DELETE: End
1207       of Haskell dependencies</Literal>".  If these lines already
1208       exist in the <Filename>makefile</Filename>, then the old
1209       dependencies are deleted first.</para>
1210
1211       <para>Internally, GHC uses a script to generate the
1212       dependencies, called <command>mkdependHS</command>.  This script
1213       has some options of its own, which you might find useful.
1214       Options can be passed directly to <command>mkdependHS</command>
1215       with GHC's <literal>-optdep</literal> option.  For example, to
1216       generate the dependencies into a file called
1217       <literal>.depend</literal> instead of
1218       <literal>Makefile</literal>:</para>
1219
1220 <screen>
1221 ghc -M -optdep-f optdep.depend ...
1222 </screen>
1223       
1224       <para>The full list of options accepted by
1225       <command>mkdependHS</command> is:</para>
1226
1227       <variablelist>
1228
1229         <varlistentry>
1230           <term><option>-w</option></term>
1231           <listitem>
1232             <para>Turn off warnings about interface file shadowing.</para>
1233           </listitem>
1234         </varlistentry>
1235
1236         <varlistentry>
1237           <term><option>-f blah</option></term>
1238           <listitem>
1239             <para>Use <Filename>blah</Filename> as the makefile,
1240             rather than <Filename>makefile</Filename> or
1241             <Filename>Makefile</Filename>.  If
1242             <Filename>blah</Filename> doesn't exist,
1243             <Command>mkdependHS</Command> creates it.  We often use
1244             <Option>-f .depend</Option> to put the dependencies in
1245             <Filename>.depend</Filename> and then
1246             <Command>include</Command> the file
1247             <Filename>.depend</Filename> into
1248             <Filename>Makefile</Filename>.</para>
1249           </listitem>
1250         </varlistentry>
1251
1252         <varlistentry>
1253           <term><option>-o &lt;osuf&gt;</option></term>
1254           <listitem>
1255             <para>Use <Filename>.&lt;osuf&gt;</Filename> as the
1256             "target file" suffix ( default: <Literal>o</Literal>).
1257             Multiple <Option>-o</Option> flags are permitted (GHC2.05
1258             onwards).  Thus "<Option>-o hc -o o</Option>" will
1259             generate dependencies for <Filename>.hc</Filename> and
1260             <Filename>.o</Filename> files.</para>
1261           </listitem>
1262         </varlistentry>
1263
1264         <varlistentry>
1265           <term><option>-s &lt;suf&gt;</option></term>
1266           <listitem>
1267             <para>Make extra dependencies that declare that files with
1268             suffix
1269             <Filename>.&lt;suf&gt;&lowbar;&lt;osuf&gt;</Filename>
1270             depend on interface files with suffix
1271             <Filename>.&lt;suf&gt;&lowbar;hi</Filename>, or (for
1272             <Literal>&lcub;-&num; SOURCE &num;-&rcub;</Literal>
1273             imports) on <Filename>.hi-boot</Filename>.  Multiple
1274             <Option>-s</Option> flags are permitted.  For example,
1275             <Option>-o hc -s a -s b</Option> will make dependencies
1276             for <Filename>.hc</Filename> on <Filename>.hi</Filename>,
1277             <Filename>.a&lowbar;hc</Filename> on
1278             <Filename>.a&lowbar;hi</Filename>, and
1279             <Filename>.b&lowbar;hc</Filename> on
1280             <Filename>.b&lowbar;hi</Filename>.  (Useful in conjunction
1281             with NoFib "ways".)</para>
1282           </listitem>
1283         </varlistentry>
1284
1285         <varlistentry>
1286           <term><option>--exclude-module=&lt;file&gt;</option></term>
1287           <listitem>
1288             <para>Regard <Filename>&lt;file&gt;</Filename> as
1289             "stable"; i.e., exclude it from having dependencies on
1290             it.</para>
1291           </listitem>
1292         </varlistentry>
1293
1294         <varlistentry>
1295           <term><option>-x</option></term>
1296           <listitem>
1297             <para>same as <option>--exclude-module</option></para>
1298           </listitem>
1299         </varlistentry>
1300
1301         <varlistentry>
1302           <term><option>--exclude-directory=&lt;dirs&gt;</option></term>
1303           <listitem>
1304             <para>Regard the colon-separated list of directories
1305             <Filename>&lt;dirs&gt;</Filename> as containing stable,
1306             don't generate any dependencies on modules therein.</para>
1307           </listitem>
1308         </varlistentry>
1309
1310         <varlistentry>
1311           <term><option>-xdirs</option></term>
1312           <listitem>
1313             <para>same as <Option>--exclude-directory</Option>.</para>
1314           </listitem>
1315         </varlistentry>
1316
1317         <varlistentry>
1318           <term><option>--include-module=&lt;file&gt;</option></term>
1319           <listitem>
1320             <para>Regard <Filename>&lt;file&gt;</Filename> as not
1321             "stable"; i.e., generate dependencies on it (if any). This
1322             option is normally used in conjunction with the
1323             <Option>--exclude-directory</Option> option.</para>
1324           </listitem>
1325         </varlistentry>
1326
1327         <varlistentry>
1328           <term><option>--include-prelude</option></term>
1329           <listitem>
1330             <para>Regard prelude libraries as unstable, i.e., generate
1331             dependencies on the prelude modules used (including
1332             <Literal>Prelude</Literal>).  This option is normally only
1333             used by the various system libraries. If a
1334             <Option>-package</Option> option is used, dependencies will
1335             also be generated on the library's interfaces.</para>
1336           </listitem>
1337         </varlistentry>
1338       </variablelist>
1339
1340 </Sect2>
1341
1342 <Sect2 id="mutual-recursion">
1343 <Title>How to compile mutually recursive modules
1344 </Title>
1345
1346 <Para>
1347 <IndexTerm><Primary>module system, recursion</Primary></IndexTerm>
1348 <IndexTerm><Primary>recursion, between modules</Primary></IndexTerm>
1349 </Para>
1350
1351 <Para>
1352 Currently, the compiler does not have proper support for dealing with
1353 mutually recursive modules:
1354 </Para>
1355
1356 <Para>
1357
1358 <ProgramListing>
1359 module A where
1360
1361 import B
1362
1363 newtype TA = MkTA Int
1364
1365 f :: TB -&#62; TA
1366 f (MkTB x) = MkTA x
1367 --------
1368 module B where
1369
1370 import A
1371
1372 data TB = MkTB !Int
1373
1374 g :: TA -&#62; TB
1375 g (MkTA x) = MkTB x
1376 </ProgramListing>
1377
1378 </Para>
1379
1380 <Para>
1381 When compiling either module A and B, the compiler will try (in vain)
1382 to look for the interface file of the other. So, to get mutually
1383 recursive modules off the ground, you need to hand write an interface
1384 file for A or B, so as to break the loop.  These hand-written
1385 interface files are called <Literal>hi-boot</Literal> files, and are placed in a file
1386 called <Filename>&lt;module&gt;.hi-boot</Filename>.  To import from an <Literal>hi-boot</Literal> file instead
1387 of the standard <Filename>.hi</Filename> file, use the following syntax in the importing module:
1388 <IndexTerm><Primary>hi-boot files</Primary></IndexTerm>
1389 <IndexTerm><Primary>importing, hi-boot files</Primary></IndexTerm>
1390 </Para>
1391
1392 <Para>
1393
1394 <ProgramListing>
1395 import {-# SOURCE #-} A
1396 </ProgramListing>
1397
1398 </Para>
1399
1400 <Para>
1401 The hand-written interface need only contain the bare minimum of
1402 information needed to get the bootstrapping process started.  For
1403 example, it doesn't need to contain declarations for <Emphasis>everything</Emphasis>
1404 that module <Literal>A</Literal> exports, only the things required by the module that
1405 imports <Literal>A</Literal> recursively.
1406 </Para>
1407
1408 <Para>
1409 For the example at hand, the boot interface file for A would look like
1410 the following:
1411 </Para>
1412
1413 <Para>
1414
1415 <ProgramListing>
1416 __interface A 1 404 where
1417 __export A TA{MkTA} ;
1418 1 newtype TA = MkTA PrelBase.Int ;
1419 </ProgramListing>
1420
1421 </Para>
1422
1423 <Para>
1424 The syntax is essentially the same as a normal <Filename>.hi</Filename> file
1425 (unfortunately), but you can usually tailor an existing <Filename>.hi</Filename> file to
1426 make a <Filename>.hi-boot</Filename> file.
1427 </Para>
1428
1429 <Para>
1430 Notice that we only put the declaration for the newtype <Literal>TA</Literal> in the
1431 <Literal>hi-boot</Literal> file, not the signature for <Function>f</Function>, since <Function>f</Function> isn't used by
1432 <Literal>B</Literal>.
1433 </Para>
1434
1435 <Para>
1436 The number &ldquo;1&rdquo; after &ldquo;&lowbar;&lowbar;interface A&rdquo; gives the version number of module A;
1437 it is incremented whenever anything in A's interface file changes.  The &ldquo;404&rdquo; is
1438 the version number of the interface file <Emphasis>syntax</Emphasis>; we change it when
1439 we change the syntax of interface files so that you get a better error message when
1440 you try to read an old-format file with a new-format compiler.
1441 </Para>
1442
1443 <Para>
1444 The number &ldquo;1&rdquo; at the beginning of a declaration is the <Emphasis>version
1445 number</Emphasis> of that declaration: for the purposes of <Filename>.hi-boot</Filename> files
1446 these can all be set to 1.  All names must be fully qualified with the
1447 <Emphasis>original</Emphasis> module that an object comes from: for example, the
1448 reference to <Literal>Int</Literal> in the interface for <Literal>A</Literal> comes from <Literal>PrelBase</Literal>,
1449 which is a module internal to GHC's prelude.  It's a pain, but that's
1450 the way it is.
1451 </Para>
1452
1453 <Para>
1454 If you want an hi-boot file to export a data type, but you don't want to give its constructors
1455 (because the constructors aren't used by the SOURCE-importing module), you can write simply:
1456 </Para>
1457
1458 <Para>
1459
1460 <ProgramListing>
1461 __interface A 1 404 where
1462 __export A TA;
1463 1 data TA
1464 </ProgramListing>
1465
1466 </Para>
1467
1468 <Para>
1469 (You must write all the type parameters, but leave out the '=' and everything that follows it.)
1470 </Para>
1471
1472 <Para>
1473 <Emphasis>Note:</Emphasis> This is all a temporary solution, a version of the
1474 compiler that handles mutually recursive modules properly without the manual
1475 construction of interface files, is (allegedly) in the works.
1476 </Para>
1477
1478 </Sect2>
1479
1480 </Sect1>
1481
1482   <sect1 id="packages">
1483     <title>Packages</title>
1484     <indexterm><primary>packages</primary></indexterm>
1485
1486     <para>Packages are collections of libraries, conveniently grouped
1487     together as a single entity.  The package system is flexible: a
1488     package may consist of Haskell code, foreign language code (eg. C
1489     libraries), or a mixture of the two.  A package is a good way to
1490     group together related Haskell modules, and is essential if you
1491     intend to make the modules into a Windows DLL (see below).</para>
1492
1493     <para>Because packages can contain both Haskell and C libraries, they
1494     are also a good way to provide convenient access to a Haskell
1495     layer over a C library.</para>
1496
1497     <para>GHC comes with several packages (see <xref
1498     linkend="book-hslibs">), and packages can be added/removed from an
1499     existing GHC installation.</para>
1500
1501     <sect2 id="listing-packages">
1502       <title>Listing the available packages</title>
1503       <indexterm><primary>packages</primary>
1504         <secondary>listing</secondary></indexterm>
1505
1506       <para>To see what packages are currently installed, use the
1507       <literal>--list-packages</literal> option:</para>
1508       <indexterm><primary><literal>--list-packages</literal></primary>
1509       </indexterm>
1510
1511 <screen>
1512   $ ghc --list-packages
1513   gmp, rts, std, lang, concurrent, data, net, posix, text, util
1514 </screen>
1515
1516       <para>Note that your GHC installation might have a slightly
1517       different set of packages installed.</para>
1518
1519       <para>The <literal>gmp</literal> and <literal>rts</literal>
1520       packages are always present, and represent the multi-precision
1521       integer and runtime system libraries respectively.  The
1522       <literal>std</literal> package contains the Haskell prelude.
1523       The rest of the packages are optional libraries.</para>
1524
1525     </sect2>
1526
1527     <sect2 id="using-packages">
1528       <title>Using a package</title>
1529       <indexterm><primary>packages</primary>
1530         <secondary>using</secondary></indexterm>
1531       
1532       <para>To use a package, add the <literal>-package</literal> flag
1533       to the command line:</para>
1534
1535       <variablelist>
1536         <varlistentry>
1537           <term><option>-package &lt;lib&gt;</option></term>
1538           <indexterm><primary>-package &lt;lib&gt; option</primary></indexterm>
1539           <listitem>
1540             <para>This option brings into scope all the modules from
1541             package <literal>&lt;lib&gt;</literal> (they still have to
1542             be imported in your Haskell source, however).  It also
1543             causes the relevant libraries to be linked when linking is
1544             being done.</para>
1545           </listitem>
1546         </varlistentry>
1547       </variablelist>
1548
1549       <para>Some packages depend on other packages, for example the
1550       <literal>text</literal> package makes use of some of the modules
1551       in the <literal>lang</literal> package.  The package system
1552       takes care of all these dependencies, so that when you say
1553       <literal>-package text</literal> on the command line, you
1554       automatically get <literal>-package lang</literal> too.</para>
1555     </sect2>
1556
1557     <sect2 id="building-packages">
1558       <title>Building a package from Haskell source</title>
1559       <indexterm><primary>packages</primary>
1560         <secondary>building</secondary></indexterm>
1561
1562       <para>It takes some special considerations to build a new
1563       package:</para>
1564
1565       <itemizedlist>
1566         <listitem>
1567           <para>A package may contain several Haskell modules. A
1568           package may span many directories, or many packages may
1569           exist in a single directory. Packages may not be mutually
1570           recursive.</para>
1571         </listitem>
1572
1573         <listitem>
1574           <para>A package has a name
1575           (e.g. <filename>std</filename>)</para>
1576         </listitem>
1577
1578         <listitem>
1579           <para>The Haskell code in a package may be built into one or
1580           more Unix libraries (e.g. <Filename>libHSfoo.a</Filename>),
1581           or a single DLL on Windows
1582           (e.g. <Filename>HSfoo.dll</Filename>).  The restriction to a
1583           single DLL on Windows is that the package system is used to
1584           tell the compiler when it should make an inter-DLL call
1585           rather than an intra-DLL call (inter-DLL calls require an
1586           extra indirection).</para>
1587         </listitem>
1588
1589         <listitem>
1590           <para>GHC does not maintain detailed cross-package
1591           dependency information.  It does remember which modules in
1592           other packages the current module depends on, but not which
1593           things within those imported things.</para>
1594         </listitem>
1595       </itemizedlist>
1596
1597       <para>To compile a module which is to be part of a new package,
1598       use the <literal>-package-name</literal> option:</para>
1599
1600       <variablelist>
1601         <varlistentry>
1602           <term><option>-package-name &lt;foo&gt;</option></term>
1603           <indexterm><primary><literal>-package-name</literal></primary>
1604             <secondary>option</secondary></indexterm>
1605           <listitem>
1606             <para>This option is added to the command line when
1607             compiling a module that is destined to be part of package
1608             <literal>foo</literal>.  If this flag is omitted then the
1609             default package <literal>Main</literal> is assumed.</para>
1610           </listitem>
1611         </varlistentry>
1612       </variablelist>
1613
1614       <para>Failure to use the <literal>-package-name</literal> option
1615       when compiling a package will result in disaster on Windows, but
1616       is relatively harmless on Unix at the moment (it will just cause
1617       a few extra dependencies in some interface files).  However,
1618       bear in mind that we might add support for Unix shared libraries
1619       at some point in the future.</para>
1620
1621       <para>It is worth noting that on Windows, because each package
1622       is built as a DLL, and a reference to a DLL costs an extra
1623       indirection, intra-package references are cheaper than
1624       inter-package references. Of course, this applies to the
1625       <Filename>Main</Filename> package as well.</para>
1626
1627     </sect2>
1628     <sect2 id="package-management">
1629       <title>Package management</title>
1630       <indexterm><primary>packages</primary>
1631         <secondary>management</secondary></indexterm>
1632       
1633       <para>GHC uses a package configuration file, called
1634       <literal>packages.conf</literal>, which can be found in your GHC
1635       install directory.  This file isn't intended to be edited
1636       directly, instead GHC provides options for adding & removing
1637       packages:</para>
1638
1639       <variablelist>
1640         <varlistentry>
1641           <term><option>--add-package</option></term>
1642           <indexterm><primary><literal>--add-package</literal></primary>
1643               <secondary>option</secondary></indexterm>
1644           <listitem>
1645             <para>Reads a package specification (see below) on stdin,
1646             and adds it to the database of installed packages.  The
1647             package specification must be a package that isn't already
1648             installed.</para>
1649           </listitem>
1650         </varlistentry>
1651
1652         <varlistentry>
1653           <term><option>--delete-package &lt;foo&gt;</option></term>
1654           <indexterm><primary><literal>--delete-package</literal></primary>
1655               <secondary>option</secondary></indexterm>
1656           <listitem>
1657             <para>Removes the specified package from the installed
1658             configuration.</para>
1659           </listitem>
1660         </varlistentry>
1661       </variablelist>
1662
1663       <para>In both cases, the old package configuration file is saved
1664       in <literal>packages.conf.old</literal> in your GHC install
1665       directory, so in an emergency you can always copy this file into
1666       <literal>package.conf</literal> to restore the old
1667       settings.</para>
1668
1669       <para>A package specification looks like this:</para>
1670
1671 <screen>
1672  ("mypkg",
1673   "4.08",
1674   Package
1675        {
1676         import_dirs     =  ["/usr/local/lib/imports/mypkg"],
1677         library_dirs    =  ["/usr/local/lib"],
1678         hs_libraries    =  ["HSmypkg" ],
1679         extra_libraries =  ["HSmypkg_cbits"],
1680         include_dirs    =  [],
1681         c_includes      =  ["HsMyPkg.h"],
1682         package_deps    =  ["text", "data"],
1683         extra_ghc_opts  =  [],
1684         extra_cc_opts   =  [],
1685         extra_ld_opts   =  ["-lmy_clib"]
1686        }
1687  )
1688 </screen>
1689
1690       <para>The first line is the name of the package, for use with
1691       the <literal>-package</literal> flag and as listed in the
1692       <literal>--list-packages</literal> list.  The second line is the
1693       version of GHC that was used to compile any Haskell code in this
1694       package (GHC will refuse to add the package if its version
1695       number differs from this one).  The rest of the components of
1696       the package specification may be specified in any order, and
1697       are:</para>
1698
1699       <variablelist>
1700         <varlistentry>
1701           <term><literal>import_dirs</literal></term>
1702           <indexterm><primary><literal>import_dirs</literal></primary>
1703             <secondary>package specification</secondary></indexterm>
1704           <listitem>
1705             <para>A list of directories containing interface files
1706             (<literal>.hi</literal> files) for this package.</para>
1707           </listitem>
1708         </varlistentry>
1709
1710         <varlistentry>
1711           <term><literal>library_dirs</literal></term>
1712           <indexterm><primary><literal>library_dirs</literal></primary>
1713             <secondary>package specification</secondary></indexterm>
1714           <listitem>
1715             <para>A list of directories containing libraries for this
1716             package.</para>
1717           </listitem>
1718         </varlistentry>
1719
1720         <varlistentry>
1721           <term><literal>hs_libraries</literal></term>
1722           <indexterm><primary><literal>hs_libraries</literal></primary>
1723             <secondary>package specification</secondary></indexterm>
1724           <listitem>
1725             <para>A list of libraries containing Haskell code for this
1726             package, with the <literal>.a</literal> or
1727             <literal>.dll</literal> suffix omitted.  On Unix, the
1728             <literal>lib</literal> prefix is also omitted.</para>
1729           </listitem>
1730         </varlistentry>
1731
1732         <varlistentry>
1733           <term><literal>extra_libraries</literal></term>
1734           <indexterm><primary><literal>extra_libraries</literal></primary>
1735             <secondary>package specification</secondary></indexterm>
1736           <listitem>
1737             <para>A list of extra libraries for this package.  The
1738             difference between <literal>hs_libraries</literal> and
1739             <literal>extra_libraries</literal> is that
1740             <literal>hs_libraries</literal> normally have several
1741             versions, to support profiling, parallel and other build
1742             options.  The various versions are given different
1743             suffixes to distinguish them, for example the profiling
1744             version of the standard prelude library is named
1745             <filename>libHSstd_p.a</filename>, with the
1746             <literal>_p</literal> indicating that this is a profiling
1747             version.  The suffix is added automatically by GHC for
1748             <literal>hs_libraries</literal> only, no suffix is added
1749             for libraries in
1750             <literal>extra_libraries</literal>.</para>
1751
1752             <para>Also, <literal>extra_libraries</literal> are placed
1753             on the linker command line before the
1754             <literal>hs_libraries</literal> for the same package.  If
1755             your package has dependencies in the other direction, you
1756             might need to make two separate packages.</para>
1757           </listitem>
1758         </varlistentry>
1759
1760         <varlistentry>
1761           <term><literal>include_dirs</literal></term>
1762           <indexterm><primary><literal>include_dirs</literal></primary>
1763             <secondary>package specification</secondary></indexterm>
1764           <listitem>
1765             <para>A list of directories containing C includes for this
1766             package (maybe the empty list).</para>
1767           </listitem>
1768         </varlistentry>
1769
1770         <varlistentry>
1771           <term><literal>c_includes</literal></term>
1772           <indexterm><primary><literal>c_includes</literal></primary>
1773             <secondary>package specification</secondary></indexterm>
1774           <listitem>
1775             <para>A list of files to include for via-C compilations
1776             using this package.  Typically this include file will
1777             contain function prototypes for any C functions used in
1778             the package, in case they end up being called as a result
1779             of Haskell functions from the package being
1780             inlined.</para>
1781           </listitem>
1782         </varlistentry>
1783
1784         <varlistentry>
1785           <term><literal>package_deps</literal></term>
1786           <indexterm><primary><literal>package_deps</literal></primary>
1787             <secondary>package specification</secondary></indexterm>
1788           <listitem>
1789             <para>A list of packages which this package depends
1790             on.</para>
1791           </listitem>
1792         </varlistentry>
1793
1794         <varlistentry>
1795           <term><literal>extra_ghc_opts</literal></term>
1796           <indexterm><primary><literal>extra_ghc_opts</literal></primary>
1797             <secondary>package specification</secondary></indexterm>
1798           <listitem>
1799             <para>Extra arguments to be added to the GHC command line
1800             when this package is being used.</para>
1801           </listitem>
1802         </varlistentry>
1803
1804         <varlistentry>
1805           <term><literal>extra_cc_opts</literal></term>
1806           <indexterm><primary><literal>extra_cc_opts</literal></primary>
1807             <secondary>package specification</secondary></indexterm>
1808           <listitem>
1809             <para>Extra arguments to be added to the gcc command line
1810             when this package is being used (only for via-C
1811             compilations).</para>
1812           </listitem>
1813         </varlistentry>
1814
1815         <varlistentry>
1816           <term><literal>extra_ld_opts</literal></term>
1817           <indexterm><primary><literal>extra_ld_opts</literal></primary>
1818             <secondary>package specification</secondary></indexterm>
1819           <listitem>
1820             <para>Extra arguments to be added to the gcc command line
1821             (for linking) when this package is being used.</para>
1822           </listitem>
1823         </varlistentry>
1824       </variablelist>
1825
1826       <para>For examples of more package specifications, take a look
1827       at the <literal>package.conf</literal> in your GHC
1828       installation.</para>
1829     </sect2>
1830   </sect1>
1831
1832
1833 <Sect1 id="options-optimise">
1834 <Title>Optimisation (code improvement)
1835 </Title>
1836
1837 <Para>
1838 <IndexTerm><Primary>optimisation (GHC)</Primary></IndexTerm>
1839 <IndexTerm><Primary>improvement, code (GHC)</Primary></IndexTerm>
1840 </Para>
1841
1842 <Para>
1843 The <Option>-O*</Option> options specify convenient &ldquo;packages&rdquo; of optimisation
1844 flags; the <Option>-f*</Option> options described later on specify
1845 <Emphasis>individual</Emphasis> optimisations to be turned on/off; the <Option>-m*</Option>
1846 options specify <Emphasis>machine-specific</Emphasis> optimisations to be turned
1847 on/off.
1848 </Para>
1849
1850 <Sect2 id="optimise-pkgs">
1851 <Title><Option>-O*</Option>: convenient &ldquo;packages&rdquo; of optimisation flags.
1852 </Title>
1853
1854 <Para>
1855 <IndexTerm><Primary>-O options</Primary></IndexTerm>
1856 </Para>
1857
1858 <Para>
1859 There are <Emphasis>many</Emphasis> options that affect the quality of code
1860 produced by GHC.  Most people only have a general goal, something like
1861 &ldquo;Compile quickly&rdquo; or &ldquo;Make my program run like greased lightning.&rdquo;
1862 The following &ldquo;packages&rdquo; of optimisations (or lack thereof) should
1863 suffice.
1864 </Para>
1865
1866 <Para>
1867 Once you choose a <Option>-O*</Option> &ldquo;package,&rdquo; stick with it&mdash;don't chop and
1868 change.  Modules' interfaces <Emphasis>will</Emphasis> change with a shift to a new
1869 <Option>-O*</Option> option, and you may have to recompile a large chunk of all
1870 importing modules before your program can again be run
1871 safely (see <XRef LinkEnd="recomp">).
1872 </Para>
1873
1874 <Para>
1875 <VariableList>
1876
1877 <VarListEntry>
1878 <Term>No <Option>-O*</Option>-type option specified:</Term>
1879 <IndexTerm><Primary>-O* not specified</Primary></IndexTerm>
1880 <ListItem>
1881 <Para>
1882 This is taken to mean: &ldquo;Please compile quickly; I'm not over-bothered
1883 about compiled-code quality.&rdquo;  So, for example: <Command>ghc -c Foo.hs</Command>
1884 </Para>
1885 </ListItem>
1886 </VarListEntry>
1887 <VarListEntry>
1888 <Term><Option>-O</Option> or <Option>-O1</Option>:</Term>
1889 <IndexTerm><Primary>-O option</Primary></IndexTerm>
1890 <IndexTerm><Primary>-O1 option</Primary></IndexTerm>
1891 <IndexTerm><Primary>optimise</Primary><secondary>normally</secondary></IndexTerm>
1892 <ListItem>
1893 <Para>
1894 Means: &ldquo;Generate good-quality code without taking too long about
1895 it.&rdquo; Thus, for example: <Command>ghc -c -O Main.lhs</Command>
1896 </Para>
1897 </ListItem>
1898 </VarListEntry>
1899 <VarListEntry>
1900 <Term><Option>-O2</Option>:</Term>
1901 <IndexTerm><Primary>-O2 option</Primary></IndexTerm>
1902 <IndexTerm><Primary>optimise</Primary><secondary>aggressively</secondary></IndexTerm>
1903 <ListItem>
1904 <Para>
1905 Means: &ldquo;Apply every non-dangerous optimisation, even if it means
1906 significantly longer compile times.&rdquo;
1907 </Para>
1908
1909 <Para>
1910 The avoided &ldquo;dangerous&rdquo; optimisations are those that can make
1911 runtime or space <Emphasis>worse</Emphasis> if you're unlucky.  They are
1912 normally turned on or off individually.
1913 </Para>
1914
1915 <Para>
1916 At the moment, <Option>-O2</Option> is <Emphasis>unlikely</Emphasis> to produce
1917 better code than <Option>-O</Option>.
1918 </Para>
1919 </ListItem>
1920 </VarListEntry>
1921 <VarListEntry>
1922 <Term><Option>-O2-for-C</Option>:</Term>
1923 <IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm>
1924 <IndexTerm><Primary>gcc, invoking with -O2</Primary></IndexTerm>
1925 <ListItem>
1926 <Para>
1927 Says to run GCC with <Option>-O2</Option>, which may be worth a few percent in
1928 execution speed.  Don't forget <Option>-fvia-C</Option>, lest you use the native-code
1929 generator and bypass GCC altogether!
1930 </Para>
1931 </ListItem>
1932 </VarListEntry>
1933 <VarListEntry>
1934 <Term><Option>-Onot</Option>:</Term>
1935 <IndexTerm><Primary>-Onot option</Primary></IndexTerm>
1936 <IndexTerm><Primary>optimising, reset</Primary></IndexTerm>
1937 <ListItem>
1938 <Para>
1939 This option will make GHC &ldquo;forget&rdquo; any
1940 <Option>-O</Option>ish options it has seen so far.  Sometimes useful;
1941 for example: <Command>make all
1942 EXTRA&lowbar;HC&lowbar;OPTS=-Onot</Command>.
1943 </Para>
1944 </ListItem>
1945 </VarListEntry>
1946 <VarListEntry>
1947 <Term><Option>-Ofile &lt;file&gt;</Option>:</Term>
1948 <IndexTerm><Primary>-Ofile &lt;file&gt; option</Primary></IndexTerm>
1949 <IndexTerm><Primary>optimising, customised</Primary></IndexTerm>
1950 <ListItem>
1951 <Para>
1952 For those who need <Emphasis>absolute</Emphasis> control over
1953 <Emphasis>exactly</Emphasis> what options are used (e.g., compiler
1954 writers, sometimes :-), a list of options can be put in a file and
1955 then slurped in with <Option>-Ofile</Option>.
1956 </Para>
1957
1958 <Para>
1959 In that file, comments are of the
1960 <Literal>&num;</Literal>-to-end-of-line variety; blank lines and most
1961 whitespace is ignored.
1962 </Para>
1963
1964 <Para>
1965 Please ask if you are baffled and would like an example of <Option>-Ofile</Option>!
1966 </Para>
1967 </ListItem>
1968 </VarListEntry>
1969 </VariableList>
1970 </Para>
1971
1972 <Para>
1973 At Glasgow, we don't use a <Option>-O*</Option> flag for day-to-day work.  We use
1974 <Option>-O</Option> to get respectable speed; e.g., when we want to measure
1975 something.  When we want to go for broke, we tend to use <Option>-O -fvia-C
1976 -O2-for-C</Option> (and we go for lots of coffee breaks).
1977 </Para>
1978
1979 <Para>
1980 The easiest way to see what <Option>-O</Option> (etc.) &ldquo;really mean&rdquo; is to run with
1981 <Option>-v</Option>, then stand back in amazement.  Alternatively, just look at the
1982 <Literal>HsC&lowbar;minus&lt;blah&gt;</Literal> lists in the GHC driver script.
1983 </Para>
1984
1985 </Sect2>
1986
1987 <Sect2>
1988 <Title><Option>-f*</Option>: platform-independent flags</Title>
1989
1990 <Para>
1991 <IndexTerm><Primary>-f* options (GHC)</Primary></IndexTerm>
1992 <IndexTerm><Primary>-fno-* options (GHC)</Primary></IndexTerm>
1993 </Para>
1994
1995 <Para>
1996 Flags can be turned <Emphasis>off</Emphasis> individually.  (NB: I hope you have a
1997 good reason for doing this&hellip;) To turn off the <Option>-ffoo</Option> flag, just use
1998 the <Option>-fno-foo</Option> flag.<IndexTerm><Primary>-fno-&lt;opt&gt; anti-option</Primary></IndexTerm> So, for
1999 example, you can say <Option>-O2 -fno-strictness</Option>, which will then drop out
2000 any running of the strictness analyser.
2001 </Para>
2002
2003 <Para>
2004 The options you are most likely to want to turn off are:
2005
2006 <ItemizedList>
2007 <ListItem>
2008
2009 <Para>
2010 <Option>-fno-strictness</Option><IndexTerm><Primary>-fno-strictness option</Primary></IndexTerm> (strictness
2011 analyser, because it is sometimes slow),
2012 </Para>
2013 </ListItem>
2014 <ListItem>
2015
2016 <Para>
2017 <Option>-fno-specialise</Option><IndexTerm><Primary>-fno-specialise option</Primary></IndexTerm> (automatic
2018 specialisation of overloaded functions, because it can make your code
2019 bigger) (US spelling also accepted), and
2020 </Para>
2021 </ListItem>
2022 <ListItem>
2023
2024 <Para>
2025 <Option>-fno-cpr-analyse</Option><IndexTerm><Primary>-fno-cpr-analyse option</Primary></IndexTerm> switches off the CPR (constructed product
2026 result) analyser.
2027 </Para>
2028 </ListItem>
2029
2030 </ItemizedList>
2031
2032 </Para>
2033
2034 <Para>
2035 Should you wish to turn individual flags <Emphasis>on</Emphasis>, you are advised
2036 to use the <Option>-Ofile</Option> option, described above.  Because the order in
2037 which optimisation passes are run is sometimes crucial, it's quite
2038 hard to do with command-line options.
2039 </Para>
2040
2041 <Para>
2042 Here are some &ldquo;dangerous&rdquo; optimisations you <Emphasis>might</Emphasis> want to try:
2043 <VariableList>
2044
2045 <VarListEntry>
2046 <Term><Option>-fvia-C</Option>:</Term>
2047 <ListItem>
2048 <Para>
2049 <IndexTerm><Primary>-fvia-C option</Primary></IndexTerm>
2050 <IndexTerm><Primary>native code generator, turning off</Primary></IndexTerm>
2051 </Para>
2052
2053 <Para>
2054 Compile via C, and don't use the native-code generator.  (There are many
2055 cases when GHC does this on its own.) You might pick up a little bit of
2056 speed by compiling via C (e.g. for floating-point intensive code on Intel).
2057 If you use <Function>&lowbar;casm&lowbar;</Function>s (which are utterly
2058 deprecated), you probably <Emphasis>have</Emphasis> to use
2059 <Option>-fvia-C</Option>.
2060 </Para>
2061
2062 <Para>
2063 The lower-case incantation, <Option>-fvia-c</Option>, is synonymous.
2064 </Para>
2065
2066 <Para>
2067 Compiling via C will probably be slower (in compilation time) than
2068 using GHC's native code generator.
2069 </Para>
2070 </ListItem>
2071 </VarListEntry>
2072 <VarListEntry>
2073 <Term><Option>-funfolding-interface-threshold&lt;n&gt;</Option>:</Term>
2074 <ListItem>
2075 <Para>
2076 <IndexTerm><Primary>-funfolding-interface-threshold option</Primary></IndexTerm>
2077 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
2078 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
2079 (Default: 30) By raising or lowering this number, you can raise or
2080 lower the amount of pragmatic junk that gets spewed into interface
2081 files.  (An unfolding has a &ldquo;size&rdquo; that reflects the cost in terms
2082 of &ldquo;code bloat&rdquo; of expanding that unfolding in another module.  A
2083 bigger function would be assigned a bigger cost.)
2084 </Para>
2085 </ListItem>
2086 </VarListEntry>
2087 <VarListEntry>
2088 <Term><Option>-funfolding-creation-threshold&lt;n&gt;</Option>:</Term>
2089 <ListItem>
2090 <Para>
2091 <IndexTerm><Primary>-funfolding-creation-threshold option</Primary></IndexTerm>
2092 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
2093 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
2094 (Default: 30) This option is similar to
2095 <Option>-funfolding-interface-threshold</Option>, except that it governs unfoldings
2096 within a single module.  Increasing this figure is more likely to
2097 result in longer compile times than faster code.  The next option is
2098 more useful:
2099 </Para>
2100 </ListItem>
2101 </VarListEntry>
2102 <VarListEntry>
2103 <Term><Option>-funfolding-use-threshold&lt;n&gt;</Option>:</Term>
2104 <ListItem>
2105 <Para>
2106 <IndexTerm><Primary>-funfolding-use-threshold option</Primary></IndexTerm>
2107 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
2108 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
2109 (Default: 8) This is the magic cut-off figure for unfolding: below
2110 this size, a function definition will be unfolded at the call-site,
2111 any bigger and it won't.  The size computed for a function depends on
2112 two things: the actual size of the expression minus any discounts that
2113 apply (see <Option>-funfolding-con-discount</Option>).
2114 </Para>
2115 </ListItem>
2116 </VarListEntry>
2117 <VarListEntry>
2118 <Term><Option>-funfolding-con-discount&lt;n&gt;</Option>:</Term>
2119 <ListItem>
2120 <Para>
2121 <IndexTerm><Primary>-funfolding-con-discount option</Primary></IndexTerm>
2122 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
2123 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
2124 (Default: 2) If the compiler decides that it can eliminate some
2125 computation by performing an unfolding, then this is a discount factor
2126 that it applies to the funciton size before deciding whether to unfold
2127 it or not.
2128 </Para>
2129
2130 <Para>
2131 OK, folks, these magic numbers `30', `8', and '2' are mildly
2132 arbitrary; they are of the &ldquo;seem to be OK&rdquo; variety.  The `8' is the
2133 more critical one; it's what determines how eager GHC is about
2134 expanding unfoldings.
2135 </Para>
2136 </ListItem>
2137 </VarListEntry>
2138 <VarListEntry>
2139 <Term><Option>-funbox-strict-fields</Option>:</Term>
2140 <ListItem>
2141 <Para>
2142 <IndexTerm><Primary>-funbox-strict-fields option</Primary></IndexTerm>
2143 <IndexTerm><Primary>strict constructor fields</Primary></IndexTerm>
2144 <IndexTerm><Primary>constructor fields, strict</Primary></IndexTerm>
2145 </Para>
2146
2147 <Para>
2148 This option causes all constructor fields which are marked strict
2149 (i.e. &ldquo;!&rdquo;) to be unboxed or unpacked if possible.  For example:
2150 </Para>
2151
2152 <Para>
2153
2154 <ProgramListing>
2155 data T = T !Float !Float
2156 </ProgramListing>
2157
2158 </Para>
2159
2160 <Para>
2161 will create a constructor <Literal>T</Literal> containing two unboxed floats if the
2162 <Option>-funbox-strict-fields</Option> flag is given.  This may not always be an
2163 optimisation: if the <Function>T</Function> constructor is scrutinised and the floats
2164 passed to a non-strict function for example, they will have to be
2165 reboxed (this is done automatically by the compiler).
2166 </Para>
2167
2168 <Para>
2169 This option should only be used in conjunction with <Option>-O</Option>, in order to
2170 expose unfoldings to the compiler so the reboxing can be removed as
2171 often as possible.  For example:
2172 </Para>
2173
2174 <Para>
2175
2176 <ProgramListing>
2177 f :: T -&#62; Float
2178 f (T f1 f2) = f1 + f2
2179 </ProgramListing>
2180
2181 </Para>
2182
2183 <Para>
2184 The compiler will avoid reboxing <Function>f1</Function> and <Function>f2</Function> by inlining <Function>+</Function> on
2185 floats, but only when <Option>-O</Option> is on.
2186 </Para>
2187
2188 <Para>
2189 Any single-constructor data is eligible for unpacking; for example
2190 </Para>
2191
2192 <Para>
2193
2194 <ProgramListing>
2195 data T = T !(Int,Int)
2196 </ProgramListing>
2197
2198 </Para>
2199
2200 <Para>
2201 will store the two <Literal>Int</Literal>s directly in the <Function>T</Function> constructor, by flattening
2202 the pair.  Multi-level unpacking is also supported:
2203 </Para>
2204
2205 <Para>
2206
2207 <ProgramListing>
2208 data T = T !S
2209 data S = S !Int !Int
2210 </ProgramListing>
2211
2212 </Para>
2213
2214 <Para>
2215 will store two unboxed <Literal>Int&num;</Literal>s directly in the <Function>T</Function> constructor.
2216 </Para>
2217 </ListItem>
2218 </VarListEntry>
2219 <VarListEntry>
2220 <Term><Option>-fsemi-tagging</Option>:</Term>
2221 <ListItem>
2222 <Para>
2223 This option (which <Emphasis>does not work</Emphasis> with the native-code generator)
2224 tells the compiler to add extra code to test for already-evaluated
2225 values.  You win if you have lots of such values during a run of your
2226 program, you lose otherwise.  (And you pay in extra code space.)
2227 </Para>
2228
2229 <Para>
2230 We have not played with <Option>-fsemi-tagging</Option> enough to recommend it.
2231 (For all we know, it doesn't even work anymore&hellip; Sigh.)
2232 </Para>
2233 </ListItem>
2234 </VarListEntry>
2235 <VarListEntry>
2236 <Term><Option>-fexcess-precision</Option>:</Term>
2237 <ListItem>
2238 <Para>
2239 When this option is given, intermediate floating point values can have
2240 a <Emphasis>greater</Emphasis> precision/range than the final type.
2241 Generally this is a good thing, but some programs may rely on the
2242 exact precision/range of <Literal>Float</Literal>/<Literal>Double</Literal>
2243 values and should not use this option for their compilation.
2244 </Para>
2245 </ListItem>
2246 </VarListEntry>
2247 </VariableList>
2248 </Para>
2249
2250 </Sect2>
2251
2252 <Sect2>
2253 <Title><Option>-m*</Option>: platform-specific flags</Title>
2254
2255 <Para>
2256 <IndexTerm><Primary>-m* options (GHC)</Primary></IndexTerm>
2257 <IndexTerm><Primary>platform-specific options</Primary></IndexTerm>
2258 <IndexTerm><Primary>machine-specific options</Primary></IndexTerm>
2259 </Para>
2260
2261 <Para>
2262 Some flags only make sense for particular target platforms.
2263 </Para>
2264
2265 <Para>
2266 <VariableList>
2267
2268 <VarListEntry>
2269 <Term><Option>-mv8</Option>:</Term>
2270 <ListItem>
2271 <Para>
2272 (SPARC machines)<IndexTerm><Primary>-mv8 option (SPARC only)</Primary></IndexTerm>
2273 Means to pass the like-named option to GCC; it says to use the
2274 Version 8 SPARC instructions, notably integer multiply and divide.
2275 The similiar <Option>-m*</Option> GCC options for SPARC also work, actually.
2276 </Para>
2277 </ListItem>
2278 </VarListEntry>
2279 <VarListEntry>
2280 <Term><Option>-mlong-calls</Option>:</Term>
2281 <ListItem>
2282 <Para>
2283 (HPPA machines)<IndexTerm><Primary>-mlong-calls option (HPPA only)</Primary></IndexTerm>
2284 Means to pass the like-named option to GCC.  Required for Very Big
2285 modules, maybe.  (Probably means you're in trouble&hellip;)
2286 </Para>
2287 </ListItem>
2288 </VarListEntry>
2289 <VarListEntry>
2290 <Term><Option>-monly-[32]-regs</Option>:</Term>
2291 <ListItem>
2292 <Para>
2293 (iX86 machines)<IndexTerm><Primary>-monly-N-regs option (iX86 only)</Primary></IndexTerm>
2294 GHC tries to &ldquo;steal&rdquo; four registers from GCC, for performance
2295 reasons; it almost always works.  However, when GCC is compiling some
2296 modules with four stolen registers, it will crash, probably saying:
2297
2298 <Screen>
2299 Foo.hc:533: fixed or forbidden register was spilled.
2300 This may be due to a compiler bug or to impossible asm
2301 statements or clauses.
2302 </Screen>
2303
2304 Just give some registers back with <Option>-monly-N-regs</Option>.  Try `3' first,
2305 then `2'.  If `2' doesn't work, please report the bug to us.
2306 </Para>
2307 </ListItem>
2308 </VarListEntry>
2309 </VariableList>
2310 </Para>
2311
2312 </Sect2>
2313
2314 <Sect2 id="optimise-C-compiler">
2315 <Title>Code improvement by the C compiler.
2316 </Title>
2317
2318 <Para>
2319 <IndexTerm><Primary>optimisation by GCC</Primary></IndexTerm>
2320 <IndexTerm><Primary>GCC optimisation</Primary></IndexTerm>
2321 </Para>
2322
2323 <Para>
2324 The C&nbsp;compiler (GCC) is run with <Option>-O</Option> turned on.  (It has
2325 to be, actually).
2326 </Para>
2327
2328 <Para>
2329 If you want to run GCC with <Option>-O2</Option>&mdash;which may be worth a few
2330 percent in execution speed&mdash;you can give a
2331 <Option>-O2-for-C</Option><IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm> option.
2332 </Para>
2333
2334 </Sect2>
2335
2336 </Sect1>
2337
2338 <Sect1 id="options-phases">
2339 <Title>Options related to a particular phase
2340 </Title>
2341
2342 <Sect2 id="c-pre-processor">
2343 <Title>The C pre-processor
2344 </Title>
2345
2346 <Para>
2347 <IndexTerm><Primary>pre-processing: cpp</Primary></IndexTerm>
2348 <IndexTerm><Primary>C pre-processor options</Primary></IndexTerm>
2349 <IndexTerm><Primary>cpp, pre-processing with</Primary></IndexTerm>
2350 </Para>
2351
2352 <Para>
2353 The C pre-processor <Command>cpp</Command> is run over your Haskell code only if the
2354 <Option>-cpp</Option> option <IndexTerm><Primary>-cpp option</Primary></IndexTerm> is given.  Unless you are
2355 building a large system with significant doses of conditional
2356 compilation, you really shouldn't need it.
2357 <VariableList>
2358
2359 <VarListEntry>
2360 <Term><Option>-D&lt;foo&gt;</Option>:</Term>
2361 <ListItem>
2362 <Para>
2363 <IndexTerm><Primary>-D&lt;name&gt; option</Primary></IndexTerm>
2364 Define macro <Constant>&lt;foo&gt;</Constant> in the usual way.  NB: does <Emphasis>not</Emphasis> affect
2365 <Option>-D</Option> macros passed to the C&nbsp;compiler when compiling via C!  For those,
2366 use the <Option>-optc-Dfoo</Option> hack&hellip; (see <XRef LinkEnd="forcing-options-through">).
2367 </Para>
2368 </ListItem>
2369 </VarListEntry>
2370 <VarListEntry>
2371 <Term><Option>-U&lt;foo&gt;</Option>:</Term>
2372 <ListItem>
2373 <Para>
2374 <IndexTerm><Primary>-U&lt;name&gt; option</Primary></IndexTerm>
2375 Undefine macro <Command>&lt;foo&gt;</Command> in the usual way.
2376 </Para>
2377 </ListItem>
2378 </VarListEntry>
2379 <VarListEntry>
2380 <Term><Option>-I&lt;dir&gt;</Option>:</Term>
2381 <ListItem>
2382 <Para>
2383 <IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
2384 Specify a directory in which to look for <Literal>&num;include</Literal> files, in
2385 the usual C way.
2386 </Para>
2387 </ListItem>
2388 </VarListEntry>
2389 </VariableList>
2390 </Para>
2391
2392 <Para>
2393 The GHC driver pre-defines several macros when processing Haskell
2394 source code (<Filename>.hs</Filename> or <Filename>.lhs</Filename> files):
2395 </Para>
2396
2397 <Para>
2398 <VariableList>
2399
2400 <VarListEntry>
2401 <Term><Constant>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Constant>:</Term>
2402 <ListItem>
2403 <Para>
2404 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Primary></IndexTerm>
2405 If defined, this means that GHC supports the language defined by the
2406 Haskell 98 report.
2407 </Para>
2408 </ListItem>
2409 </VarListEntry>
2410 <VarListEntry>
2411 <Term><Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;=98</Constant>:</Term>
2412 <ListItem>
2413 <Para>
2414 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Primary></IndexTerm>
2415 In GHC 4.04 and later, the <Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Constant> macro is defined as having
2416 the value <Constant>98</Constant>.
2417 </Para>
2418 </ListItem>
2419 </VarListEntry>
2420 <VarListEntry>
2421 <Term><Constant>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar;</Constant>:</Term>
2422 <ListItem>
2423 <Para>
2424 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar; macro</Primary></IndexTerm>
2425 If defined to <Emphasis>n</Emphasis>, that means GHC supports the Haskell language
2426 defined in the Haskell report version <Emphasis>1.n</Emphasis>.  Currently 5.  This
2427 macro is deprecated, and will probably disappear in future versions.
2428 </Para>
2429 </ListItem>
2430 </VarListEntry>
2431 <VarListEntry>
2432 <Term><Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
2433 <ListItem>
2434 <Para>
2435 <IndexTerm><Primary>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
2436 For version <Emphasis>n</Emphasis> of the GHC system, this will be <Literal>&num;define</Literal>d to
2437 <Emphasis>100n</Emphasis>.  So, for version 4.00, it is 400.
2438 </Para>
2439
2440 <Para>
2441 With any luck, <Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant> will be undefined in all other
2442 implementations that support C-style pre-processing.
2443 </Para>
2444
2445 <Para>
2446 (For reference: the comparable symbols for other systems are:
2447 <Constant>&lowbar;&lowbar;HUGS&lowbar;&lowbar;</Constant> for Hugs and <Constant>&lowbar;&lowbar;HBC&lowbar;&lowbar;</Constant> for Chalmers.)
2448 </Para>
2449
2450 <Para>
2451 NB. This macro is set when pre-processing both Haskell source and C
2452 source, including the C source generated from a Haskell module
2453 (i.e. <Filename>.hs</Filename>, <Filename>.lhs</Filename>, <Filename>.c</Filename> and <Filename>.hc</Filename> files).
2454 </Para>
2455 </ListItem>
2456 </VarListEntry>
2457 <VarListEntry>
2458 <Term><Constant>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
2459 <ListItem>
2460 <Para>
2461 <IndexTerm><Primary>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
2462 This symbol is defined when pre-processing Haskell (input) and
2463 pre-processing C (GHC output).  Since GHC from verion 4.00 now
2464 supports concurrent haskell by default, this symbol is always defined.
2465 </Para>
2466 </ListItem>
2467 </VarListEntry>
2468 <VarListEntry>
2469 <Term><Constant>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
2470 <ListItem>
2471 <Para>
2472 <IndexTerm><Primary>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
2473 Only defined when <Option>-parallel</Option> is in use!  This symbol is defined when
2474 pre-processing Haskell (input) and pre-processing C (GHC output).
2475 </Para>
2476 </ListItem>
2477 </VarListEntry>
2478 </VariableList>
2479 </Para>
2480
2481 <Para>
2482 Options other than the above can be forced through to the C
2483 pre-processor with the <Option>-opt</Option> flags (see
2484 <XRef LinkEnd="forcing-options-through">).
2485 </Para>
2486
2487 <Para>
2488 A small word of warning: <Option>-cpp</Option> is not friendly to &ldquo;string
2489 gaps&rdquo;.<IndexTerm><Primary>-cpp vs string gaps</Primary></IndexTerm><IndexTerm><Primary>string gaps vs
2490 -cpp</Primary></IndexTerm>.  In other words, strings such as the following:
2491 </Para>
2492
2493 <Para>
2494
2495 <ProgramListing>
2496 strmod = "\
2497 \ p \
2498 \ "
2499 </ProgramListing>
2500
2501 </Para>
2502
2503 <Para>
2504 don't work with <Option>-cpp</Option>; <Filename>/usr/bin/cpp</Filename> elides the
2505 backslash-newline pairs.
2506 </Para>
2507
2508 <Para>
2509 However, it appears that if you add a space at the end of the line,
2510 then <Command>cpp</Command> (at least GNU <Command>cpp</Command> and possibly other <Command>cpp</Command>s)
2511 leaves the backslash-space pairs alone and the string gap works as
2512 expected.
2513 </Para>
2514
2515 </Sect2>
2516
2517 <Sect2 id="options-C-compiler">
2518 <Title>Options affecting the C compiler (if applicable)
2519 </Title>
2520
2521 <Para>
2522 <IndexTerm><Primary>include-file options</Primary></IndexTerm>
2523 <IndexTerm><Primary>C compiler options</Primary></IndexTerm>
2524 <IndexTerm><Primary>GCC options</Primary></IndexTerm>
2525 </Para>
2526
2527 <Para>
2528 At the moment, quite a few common C-compiler options are passed on
2529 quietly to the C compilation of Haskell-compiler-generated C files.
2530 THIS MAY CHANGE.  Meanwhile, options so sent are:
2531 </Para>
2532
2533 <Para>
2534
2535 <InformalTable>
2536 <TGroup Cols="2">
2537 <ColSpec Align="Left" Colsep="0">
2538 <ColSpec Align="Left" Colsep="0">
2539 <TBody>
2540 <Row>
2541 <Entry><Option>-ansi</Option> </Entry>
2542 <Entry> do ANSI C (not K&amp;R) </Entry>
2543 </Row>
2544 <Row>
2545 <Entry>
2546 <Option>-pedantic</Option> </Entry>
2547 <Entry> be so</Entry>
2548 </Row>
2549 <Row>
2550 <Entry>
2551 <Option>-dgcc-lint</Option> </Entry>
2552 <Entry> (hack) short for &ldquo;make GCC very paranoid&rdquo;</Entry>
2553 </Row>
2554
2555 </TBody>
2556
2557 </TGroup>
2558 </InformalTable>
2559
2560 <IndexTerm><Primary>-ansi option (for GCC)</Primary></IndexTerm>
2561 <IndexTerm><Primary>-pedantic option (for GCC)</Primary></IndexTerm>
2562 <IndexTerm><Primary>-dgcc-lint option (GCC paranoia)</Primary></IndexTerm>
2563 </Para>
2564
2565 <Para>
2566 If you are compiling with lots of foreign calls, you may need to
2567 tell the C&nbsp;compiler about some <Literal>&num;include</Literal> files.  There is no real
2568 pretty way to do this, but you can use this hack from the
2569 command-line:
2570 </Para>
2571
2572 <Para>
2573
2574 <Screen>
2575 % ghc -c '-#include &#60;X/Xlib.h&#62;' Xstuff.lhs
2576 </Screen>
2577
2578 </Para>
2579
2580 </Sect2>
2581
2582 <Sect2 id="options-linker">
2583 <Title>Linking and consistency-checking
2584 </Title>
2585
2586 <Para>
2587 <IndexTerm><Primary>linker options</Primary></IndexTerm>
2588 <IndexTerm><Primary>ld options</Primary></IndexTerm>
2589 </Para>
2590
2591 <Para>
2592 GHC has to link your code with various libraries, possibly including:
2593 user-supplied, GHC-supplied, and system-supplied (<Option>-lm</Option> math
2594 library, for example).
2595 </Para>
2596
2597 <Para>
2598 <VariableList>
2599
2600 <VarListEntry>
2601 <Term><Option>-l&lt;FOO&gt;</Option>:</Term>
2602 <ListItem>
2603 <Para>
2604 <IndexTerm><Primary>-l&lt;lib&gt; option</Primary></IndexTerm>
2605 Link in a library named <Filename>lib&lt;FOO&gt;.a</Filename> which resides somewhere on the
2606 library directories path.
2607 </Para>
2608
2609 <Para>
2610 Because of the sad state of most UNIX linkers, the order of such
2611 options does matter.  Thus: <Command>ghc -lbar *.o</Command> is almost certainly
2612 wrong, because it will search <Filename>libbar.a</Filename> <Emphasis>before</Emphasis> it has
2613 collected unresolved symbols from the <Filename>*.o</Filename> files.
2614 <Command>ghc *.o -lbar</Command> is probably better.
2615 </Para>
2616
2617 <Para>
2618 The linker will of course be informed about some GHC-supplied
2619 libraries automatically; these are:
2620 </Para>
2621
2622 <Para>
2623
2624 <InformalTable>
2625 <TGroup Cols="2">
2626 <ColSpec Align="Left" Colsep="0">
2627 <ColSpec Align="Left" Colsep="0">
2628 <TBody>
2629 <Row>
2630 <Entry><Emphasis>-l equivalent</Emphasis> </Entry>
2631 <Entry> <Emphasis>description</Emphasis> </Entry>
2632 </Row>
2633
2634 <Row>
2635 <Entry>
2636 <Option>-lHSrts,-lHSclib</Option> </Entry>
2637 <Entry> basic runtime libraries </Entry>
2638 </Row>
2639 <Row>
2640 <Entry>
2641 <Option>-lHS</Option> </Entry>
2642 <Entry> standard Prelude library </Entry>
2643 </Row>
2644 <Row>
2645 <Entry>
2646 <Option>-lHS&lowbar;cbits</Option> </Entry>
2647 <Entry> C support code for standard Prelude library </Entry>
2648 </Row>
2649 <Row>
2650 <Entry>
2651 <Option>-lgmp</Option> </Entry>
2652 <Entry> GNU multi-precision library (for Integers)</Entry>
2653 </Row>
2654
2655 </TBody>
2656
2657 </TGroup>
2658 </InformalTable>
2659
2660 </Para>
2661
2662 <Para>
2663 <IndexTerm><Primary>-lHS library</Primary></IndexTerm>
2664 <IndexTerm><Primary>-lHS&lowbar;cbits library</Primary></IndexTerm>
2665 <IndexTerm><Primary>-lHSrts library</Primary></IndexTerm>
2666 <IndexTerm><Primary>-lgmp library</Primary></IndexTerm>
2667 </Para>
2668 </ListItem>
2669 </VarListEntry>
2670 <VarListEntry>
2671 <Term><Option>-package &lt;name&gt;</Option>:</Term>
2672 <ListItem>
2673 <Para>
2674 <IndexTerm><Primary>-package &lt;name&gt; option</Primary></IndexTerm>
2675 </Para>
2676
2677 <Para>
2678 If you are using a Haskell &ldquo;package&rdquo; (e.g., the POSIX
2679 library), just use the <Option>-package posix</Option> option, and the
2680 correct code should be linked in.  See <xref linkend="packages"> for
2681 more details.
2682 </Para>
2683 </ListItem>
2684 </VarListEntry>
2685 <VarListEntry>
2686 <Term><Option>-L&lt;dir&gt;</Option>:</Term>
2687 <ListItem>
2688 <Para>
2689 <IndexTerm><Primary>-L&lt;dir&gt; option</Primary></IndexTerm>
2690 Where to find user-supplied libraries&hellip;  Prepend the directory
2691 <Filename>&lt;dir&gt;</Filename> to the library directories path.
2692 </Para>
2693 </ListItem>
2694 </VarListEntry>
2695 <VarListEntry>
2696 <Term><Option>-static</Option>:</Term>
2697 <ListItem>
2698 <Para>
2699 <IndexTerm><Primary>-static option</Primary></IndexTerm>
2700 Tell the linker to avoid shared libraries.
2701 </Para>
2702 </ListItem>
2703 </VarListEntry>
2704 <VarListEntry>
2705 <Term><Option>-no-link-chk</Option> and <Option>-link-chk</Option>:</Term>
2706 <ListItem>
2707 <Para>
2708 <IndexTerm><Primary>-no-link-chk option</Primary></IndexTerm>
2709 <IndexTerm><Primary>-link-chk option</Primary></IndexTerm>
2710 <IndexTerm><Primary>consistency checking of executables</Primary></IndexTerm>
2711 By default, immediately after linking an executable, GHC verifies that
2712 the pieces that went into it were compiled with compatible flags; a
2713 &ldquo;consistency check&rdquo;.
2714 (This is to avoid mysterious failures caused by non-meshing of
2715 incompatibly-compiled programs; e.g., if one <Filename>.o</Filename> file was compiled
2716 for a parallel machine and the others weren't.)  You may turn off this
2717 check with <Option>-no-link-chk</Option>.  You can turn it (back) on with
2718 <Option>-link-chk</Option> (the default).
2719 </Para>
2720 </ListItem>
2721 </VarListEntry>
2722 <VarListEntry>
2723 <Term><Option>-no-hs-main</Option>:</Term>
2724 <ListItem>
2725 <Para>
2726 <IndexTerm><Primary>-no-hs-main option</Primary></IndexTerm>
2727 <IndexTerm><Primary>linking Haskell libraries with foreign code</Primary></IndexTerm>
2728 </Para>
2729
2730 <Para>
2731 In the event you want to include ghc-compiled code as part of another
2732 (non-Haskell) program, the RTS will not be supplying its definition of
2733 <Function>main()</Function> at link-time, you will have to. To signal that to the
2734 driver script when linking, use <Option>-no-hs-main</Option>.
2735 </Para>
2736
2737 <Para>
2738 Notice that since the command-line passed to the linker is rather
2739 involved, you probably want to use the ghc driver script to do the
2740 final link of your `mixed-language' application. This is not a
2741 requirement though, just try linking once with <Option>-v</Option> on to see what
2742 options the driver passes through to the linker.
2743 </Para>
2744 </ListItem>
2745 </VarListEntry>
2746 </VariableList>
2747 </Para>
2748
2749 </Sect2>
2750
2751 </Sect1>
2752
2753 <Sect1 id="sec-using-concurrent">
2754 <Title>Using Concurrent Haskell</Title>
2755
2756 <Para>
2757 <IndexTerm><Primary>Concurrent Haskell&mdash;use</Primary></IndexTerm>
2758 </Para>
2759
2760 <Para>
2761 GHC (as of version 4.00) supports Concurrent Haskell by default,
2762 without requiring a special option or libraries compiled in a certain
2763 way.  To get access to the support libraries for Concurrent Haskell
2764 (i.e. <Literal>Concurrent</Literal> and friends), use the
2765 <Option>-package concurrent</Option> option.
2766 </Para>
2767
2768 <Para>
2769 Three RTS options are provided for modifying the behaviour of the
2770 threaded runtime system.  See the descriptions of
2771 <Option>-C[&lt;us&gt;]</Option>, <Option>-q</Option>, and
2772 <Option>-t&lt;num&gt;</Option> in <XRef LinkEnd="parallel-rts-opts">.
2773 </Para>
2774
2775 <Para>
2776 Concurrent Haskell is described in more detail in <XRef
2777 LinkEnd="sec-Concurrent">.
2778 </Para>
2779
2780 </Sect1>
2781
2782 <Sect1 id="sec-using-parallel">
2783 <Title>Using Parallel Haskell</Title>
2784
2785 <Para>
2786 <IndexTerm><Primary>Parallel Haskell&mdash;use</Primary></IndexTerm>
2787 </Para>
2788
2789 <Para>
2790 &lsqb;You won't be able to execute parallel Haskell programs unless PVM3
2791 (Parallel Virtual Machine, version 3) is installed at your site.]
2792 </Para>
2793
2794 <Para>
2795 To compile a Haskell program for parallel execution under PVM, use the
2796 <Option>-parallel</Option> option,<IndexTerm><Primary>-parallel
2797 option</Primary></IndexTerm> both when compiling <Emphasis>and
2798 linking</Emphasis>.  You will probably want to <Literal>import
2799 Parallel</Literal> into your Haskell modules.
2800 </Para>
2801
2802 <Para>
2803 To run your parallel program, once PVM is going, just invoke it
2804 &ldquo;as normal&rdquo;.  The main extra RTS option is
2805 <Option>-N&lt;n&gt;</Option>, to say how many PVM
2806 &ldquo;processors&rdquo; your program to run on.  (For more details of
2807 all relevant RTS options, please see <XRef
2808 LinkEnd="parallel-rts-opts">.)
2809 </Para>
2810
2811 <Para>
2812 In truth, running Parallel Haskell programs and getting information
2813 out of them (e.g., parallelism profiles) is a battle with the vagaries of
2814 PVM, detailed in the following sections.
2815 </Para>
2816
2817 <Sect2>
2818 <Title>Dummy's guide to using PVM</Title>
2819
2820 <Para>
2821 <IndexTerm><Primary>PVM, how to use</Primary></IndexTerm>
2822 <IndexTerm><Primary>Parallel Haskell&mdash;PVM use</Primary></IndexTerm>
2823 Before you can run a parallel program under PVM, you must set the
2824 required environment variables (PVM's idea, not ours); something like,
2825 probably in your <Filename>.cshrc</Filename> or equivalent:
2826
2827 <ProgramListing>
2828 setenv PVM_ROOT /wherever/you/put/it
2829 setenv PVM_ARCH `$PVM_ROOT/lib/pvmgetarch`
2830 setenv PVM_DPATH $PVM_ROOT/lib/pvmd
2831 </ProgramListing>
2832
2833 </Para>
2834
2835 <Para>
2836 Creating and/or controlling your &ldquo;parallel machine&rdquo; is a purely-PVM
2837 business; nothing specific to Parallel Haskell.
2838 </Para>
2839
2840 <Para>
2841 You use the <Command>pvm</Command><IndexTerm><Primary>pvm command</Primary></IndexTerm> command to start PVM on your
2842 machine.  You can then do various things to control/monitor your
2843 &ldquo;parallel machine;&rdquo; the most useful being:
2844 </Para>
2845
2846 <Para>
2847 <InformalTable>
2848 <TGroup Cols=2>
2849 <ColSpec Align="Left">
2850 <TBody>
2851
2852 <Row>
2853 <Entry><KeyCombo><KeyCap>Control</KeyCap><KeyCap>D</KeyCap></KeyCombo></Entry>
2854 <Entry>exit <Command>pvm</Command>, leaving it running</Entry>
2855 </Row>
2856
2857 <Row>
2858 <Entry><Command>halt</Command></Entry>
2859 <Entry>kill off this &ldquo;parallel machine&rdquo; &amp; exit</Entry>
2860 </Row>
2861
2862 <Row>
2863 <Entry><Command>add &lt;host&gt;</Command></Entry>
2864 <Entry>add <Command>&lt;host&gt;</Command> as a processor</Entry>
2865 </Row>
2866
2867 <Row>
2868 <Entry><Command>delete &lt;host&gt;</Command></Entry>
2869 <Entry>delete <Command>&lt;host&gt;</Command></Entry>
2870 </Row>
2871
2872 <Row>
2873 <Entry><Command>reset</Command></Entry>
2874 <Entry>kill what's going, but leave PVM up</Entry>
2875 </Row>
2876
2877 <Row>
2878 <Entry><Command>conf</Command></Entry>
2879 <Entry>list the current configuration</Entry>
2880 </Row>
2881
2882 <Row>
2883 <Entry><Command>ps</Command></Entry>
2884 <Entry>report processes' status</Entry>
2885 </Row>
2886
2887 <Row>
2888 <Entry><Command>pstat &lt;pid&gt;</Command></Entry>
2889 <Entry>status of a particular process</Entry>
2890 </Row>
2891
2892 </TBody>
2893 </TGroup>
2894 </InformalTable>
2895 </Para>
2896
2897 <Para>
2898 The PVM documentation can tell you much, much more about <Command>pvm</Command>!
2899 </Para>
2900
2901 </Sect2>
2902
2903 <Sect2>
2904 <Title>Parallelism profiles</Title>
2905
2906 <Para>
2907 <IndexTerm><Primary>parallelism profiles</Primary></IndexTerm>
2908 <IndexTerm><Primary>profiles, parallelism</Primary></IndexTerm>
2909 <IndexTerm><Primary>visualisation tools</Primary></IndexTerm>
2910 </Para>
2911
2912 <Para>
2913 With Parallel Haskell programs, we usually don't care about the
2914 results&mdash;only with &ldquo;how parallel&rdquo; it was!  We want pretty pictures.
2915 </Para>
2916
2917 <Para>
2918 Parallelism profiles (&agrave; la <Command>hbcpp</Command>) can be generated with the
2919 <Option>-q</Option><IndexTerm><Primary>-q RTS option (concurrent, parallel)</Primary></IndexTerm> RTS option.  The
2920 per-processor profiling info is dumped into files named
2921 <Filename>&lt;full-path&gt;&lt;program&gt;.gr</Filename>.  These are then munged into a PostScript picture,
2922 which you can then display.  For example, to run your program
2923 <Filename>a.out</Filename> on 8 processors, then view the parallelism profile, do:
2924 </Para>
2925
2926 <Para>
2927
2928 <Screen>
2929 % ./a.out +RTS -N8 -q
2930 % grs2gr *.???.gr &#62; temp.gr     # combine the 8 .gr files into one
2931 % gr2ps -O temp.gr              # cvt to .ps; output in temp.ps
2932 % ghostview -seascape temp.ps   # look at it!
2933 </Screen>
2934
2935 </Para>
2936
2937 <Para>
2938 The scripts for processing the parallelism profiles are distributed
2939 in <Filename>ghc/utils/parallel/</Filename>.
2940 </Para>
2941
2942 </Sect2>
2943
2944 <Sect2>
2945 <Title>Other useful info about running parallel programs</Title>
2946
2947 <Para>
2948 The &ldquo;garbage-collection statistics&rdquo; RTS options can be useful for
2949 seeing what parallel programs are doing.  If you do either
2950 <Option>+RTS -Sstderr</Option><IndexTerm><Primary>-Sstderr RTS option</Primary></IndexTerm> or <Option>+RTS -sstderr</Option>, then
2951 you'll get mutator, garbage-collection, etc., times on standard
2952 error. The standard error of all PE's other than the `main thread'
2953 appears in <Filename>/tmp/pvml.nnn</Filename>, courtesy of PVM.
2954 </Para>
2955
2956 <Para>
2957 Whether doing <Option>+RTS -Sstderr</Option> or not, a handy way to watch
2958 what's happening overall is: <Command>tail -f /tmp/pvml.nnn</Command>.
2959 </Para>
2960
2961 </Sect2>
2962
2963 <Sect2 id="parallel-rts-opts">
2964 <Title>RTS options for Concurrent/Parallel Haskell
2965 </Title>
2966
2967 <Para>
2968 <IndexTerm><Primary>RTS options, concurrent</Primary></IndexTerm>
2969 <IndexTerm><Primary>RTS options, parallel</Primary></IndexTerm>
2970 <IndexTerm><Primary>Concurrent Haskell&mdash;RTS options</Primary></IndexTerm>
2971 <IndexTerm><Primary>Parallel Haskell&mdash;RTS options</Primary></IndexTerm>
2972 </Para>
2973
2974 <Para>
2975 Besides the usual runtime system (RTS) options
2976 (<XRef LinkEnd="runtime-control">), there are a few options particularly
2977 for concurrent/parallel execution.
2978 </Para>
2979
2980 <Para>
2981 <VariableList>
2982
2983 <VarListEntry>
2984 <Term><Option>-N&lt;N&gt;</Option>:</Term>
2985 <ListItem>
2986 <Para>
2987 <IndexTerm><Primary>-N&lt;N&gt; RTS option (parallel)</Primary></IndexTerm>
2988 (PARALLEL ONLY) Use <Literal>&lt;N&gt;</Literal> PVM processors to run this program;
2989 the default is 2.
2990 </Para>
2991 </ListItem>
2992 </VarListEntry>
2993 <VarListEntry>
2994 <Term><Option>-C[&lt;us&gt;]</Option>:</Term>
2995 <ListItem>
2996 <Para>
2997 <IndexTerm><Primary>-C&lt;us&gt; RTS option</Primary></IndexTerm> Sets
2998 the context switch interval to <Literal>&lt;s&gt;</Literal> seconds.
2999 A context switch will occur at the next heap block allocation after
3000 the timer expires (a heap block allocation occurs every 4k of
3001 allocation).  With <Option>-C0</Option> or <Option>-C</Option>,
3002 context switches will occur as often as possible (at every heap block
3003 allocation).  By default, context switches occur every 20ms
3004 milliseconds.  Note that GHC's internal timer ticks every 20ms, and
3005 the context switch timer is always a multiple of this timer, so 20ms
3006 is the maximum granularity available for timed context switches.
3007 </Para>
3008 </ListItem>
3009 </VarListEntry>
3010 <VarListEntry>
3011 <Term><Option>-q[v]</Option>:</Term>
3012 <ListItem>
3013 <Para>
3014 <IndexTerm><Primary>-q RTS option</Primary></IndexTerm>
3015 (PARALLEL ONLY) Produce a quasi-parallel profile of thread activity,
3016 in the file <FIlename>&lt;program&gt;.qp</FIlename>.  In the style of <Command>hbcpp</Command>, this profile
3017 records the movement of threads between the green (runnable) and red
3018 (blocked) queues.  If you specify the verbose suboption (<Option>-qv</Option>), the
3019 green queue is split into green (for the currently running thread
3020 only) and amber (for other runnable threads).  We do not recommend
3021 that you use the verbose suboption if you are planning to use the
3022 <Command>hbcpp</Command> profiling tools or if you are context switching at every heap
3023 check (with <Option>-C</Option>).
3024 </Para>
3025 </ListItem>
3026 </VarListEntry>
3027 <VarListEntry>
3028 <Term><Option>-t&lt;num&gt;</Option>:</Term>
3029 <ListItem>
3030 <Para>
3031 <IndexTerm><Primary>-t&lt;num&gt; RTS option</Primary></IndexTerm>
3032 (PARALLEL ONLY) Limit the number of concurrent threads per processor
3033 to <Literal>&lt;num&gt;</Literal>.  The default is 32.  Each thread requires slightly over 1K
3034 <Emphasis>words</Emphasis> in the heap for thread state and stack objects.  (For
3035 32-bit machines, this translates to 4K bytes, and for 64-bit machines,
3036 8K bytes.)
3037 </Para>
3038 </ListItem>
3039 </VarListEntry>
3040 <VarListEntry>
3041 <Term><Option>-d</Option>:</Term>
3042 <ListItem>
3043 <Para>
3044 <IndexTerm><Primary>-d RTS option (parallel)</Primary></IndexTerm>
3045 (PARALLEL ONLY) Turn on debugging.  It pops up one xterm (or GDB, or
3046 something&hellip;) per PVM processor.  We use the standard <Command>debugger</Command>
3047 script that comes with PVM3, but we sometimes meddle with the
3048 <Command>debugger2</Command> script.  We include ours in the GHC distribution,
3049 in <Filename>ghc/utils/pvm/</Filename>.
3050 </Para>
3051 </ListItem>
3052 </VarListEntry>
3053 <VarListEntry>
3054 <Term><Option>-e&lt;num&gt;</Option>:</Term>
3055 <ListItem>
3056 <Para>
3057 <IndexTerm><Primary>-e&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
3058 (PARALLEL ONLY) Limit the number of pending sparks per processor to
3059 <Literal>&lt;num&gt;</Literal>. The default is 100. A larger number may be appropriate if
3060 your program generates large amounts of parallelism initially.
3061 </Para>
3062 </ListItem>
3063 </VarListEntry>
3064 <VarListEntry>
3065 <Term><Option>-Q&lt;num&gt;</Option>:</Term>
3066 <ListItem>
3067 <Para>
3068 <IndexTerm><Primary>-Q&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
3069 (PARALLEL ONLY) Set the size of packets transmitted between processors
3070 to <Literal>&lt;num&gt;</Literal>. The default is 1024 words. A larger number may be
3071 appropriate if your machine has a high communication cost relative to
3072 computation speed.
3073 </Para>
3074 </ListItem>
3075 </VarListEntry>
3076 </VariableList>
3077 </Para>
3078
3079 </Sect2>
3080
3081 </Sect1>
3082
3083 &runtime
3084 &debug
3085
3086 </Chapter>
3087
3088 <!-- Emacs stuff:
3089      ;;; Local Variables: ***
3090      ;;; mode: sgml ***
3091      ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***
3092      ;;; End: ***
3093  -->