[project @ 2000-10-09 16:51:01 by rrt]
[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.  
893 The idea is that you can then import a Prelude of your own.  (But don't call it <Literal>Prelude</Literal>;
894 the Haskell module namespace is flat, and you must not conflict with any Prelude module.)
895 </Para>
896 <Para>
897 Even though you have not imported the Prelude, all the built-in syntax still refers to 
898 the built-in Haskell Prelude types and values, as specified by the Haskell Report.  
899 For example, the type <Literal>[Int]</Literal>
900 still means <Literal>Prelude.[] Int</Literal>; tuples continue to refer to the standard Prelude
901 tuples; the translation for list comprehensions continues to use <Literal>Prelude.map</Literal> etc.
902 </Para>
903 <Para> With one group of exceptions!  You may want to define your own numeric class hierarchy.
904 It completely defeats that purpose if the literal "1" means "<Literal>Prelude.fromInteger 1</Literal>",
905 which is what the Haskell Report specifies.  So the <Option>-fno-implicit-prelude</Option> flag causes
906 the following pieces of built-in syntax to refer to whatever is in scope, not the Prelude versions:
907 <ItemizedList>
908 <ListItem>
909 <Para>
910 Integer and fractional literals mean "<Literal>fromInteger 1</Literal>" and "<Literal>fromRational 3.2</Literal>",
911 not the Prelude-qualified versions; both in expressions and in patterns.
912 </Para>
913 </ListItem>
914 <ListItem>
915 <Para>
916 Negation (e.g. "<Literal>- (f x)</Literal>") means "<Literal>negate (f x)</Literal>" (not <Literal>Prelude.negate</Literal>).
917 </Para>
918 </ListItem>
919 <ListItem>
920 <Para>
921 In an n+k pattern, the standard Prelude <Literal>Ord</Literal> class is used for comparison, but the 
922 necessary subtraction uses 
923 whatever "<Literal>(-)</Literal>" is in scope (not "<Literal>Prelude.(-)</Literal>").
924 </Para>
925 </ListItem>
926 </ItemizedList>
927 </Para>
928 </ListItem>
929 </VarListEntry>
930
931 <VarListEntry>
932 <Term><Option>-I&lt;dir&gt;</Option></Term>
933 <ListItem>
934 <Para>
935 <IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
936 Once a Haskell module has been compiled to C (<Filename>.hc</Filename> file), you may
937 wish to specify where GHC tells the C compiler to look for <Filename>.h</Filename> files.
938 (Or, if you are using the <Option>-cpp</Option> option<IndexTerm><Primary>-cpp option</Primary></IndexTerm>, where
939 it tells the C pre-processor to look&hellip;)  For this purpose, use a <Option>-I</Option>
940 option in the usual C-ish way.
941 </Para>
942 </ListItem>
943 </VarListEntry>
944
945 </VariableList>
946 </Para>
947
948 </Sect2>
949
950 <Sect2 id="hi-options">
951 <Title>Other options related to interface files
952 </Title>
953
954 <Para>
955 <IndexTerm><Primary>interface files, options</Primary></IndexTerm>
956 The interface output may be directed to another file
957 <Filename>bar2/Wurble.iface</Filename> with the option <Option>-ohi bar2/Wurble.iface</Option><IndexTerm><Primary>-ohi
958 &lt;file&gt; option</Primary></IndexTerm> (not recommended).
959 </Para>
960
961 <Para>
962 To avoid generating an interface file at all, use a <Option>-nohi</Option>
963 option.<IndexTerm><Primary>-nohi option</Primary></IndexTerm>
964 </Para>
965
966 <Para>
967 The compiler does not overwrite an existing <Filename>.hi</Filename> interface file if
968 the new one is byte-for-byte the same as the old one; this is friendly
969 to <Command>make</Command>.  When an interface does change, it is often enlightening to
970 be informed.  The <Option>-hi-diffs</Option><IndexTerm><Primary>-hi-diffs option</Primary></IndexTerm> option will
971 make GHC run <Command>diff</Command> on the old and new <Filename>.hi</Filename> files. You can also
972 record the difference in the interface file itself, the
973 <Option>-keep-hi-diffs</Option><IndexTerm><Primary>-keep-hi-diffs</Primary></IndexTerm> option takes care of that.
974 </Para>
975
976 <Para>
977 The <Filename>.hi</Filename> files from GHC contain &ldquo;usage&rdquo; information which changes
978 often and uninterestingly.  If you really want to see these changes
979 reported, you need to use the
980 <Option>-hi-diffs-with-usages</Option><IndexTerm><Primary>-hi-diffs-with-usages option</Primary></IndexTerm>
981 option.
982 </Para>
983
984 <Para>
985 Interface files are normally jammed full of compiler-produced
986 <Emphasis>pragmas</Emphasis>, which record arities, strictness info, etc.  If you
987 think these pragmas are messing you up (or you are doing some kind of
988 weird experiment), you can tell GHC to ignore them with the
989 <Option>-fignore-interface-pragmas</Option><IndexTerm><Primary>-fignore-interface-pragmas
990 option</Primary></IndexTerm> option.
991 </Para>
992
993 <Para>
994 When compiling without optimisations on, the compiler is extra-careful
995 about not slurping in data constructors and instance declarations that
996 it will not need. If you believe it is getting it wrong and not
997 importing stuff which you think it should, this optimisation can be
998 turned off with <Option>-fno-prune-tydecls</Option> and <Option>-fno-prune-instdecls</Option>.
999 <IndexTerm><Primary>-fno-prune-tydecls option</Primary></IndexTerm><IndexTerm><Primary>-fno-prune-instdecls
1000 option</Primary></IndexTerm>
1001 </Para>
1002
1003 <Para>
1004 See also <XRef LinkEnd="options-linker">, which describes how the linker finds standard
1005 Haskell libraries.
1006 </Para>
1007
1008 </Sect2>
1009
1010 <Sect2 id="recomp">
1011 <Title>The recompilation checker
1012 </Title>
1013
1014 <IndexTerm><Primary>recompilation checker</Primary></IndexTerm>
1015
1016 <Para>
1017 <variablelist>
1018 <VarListEntry>
1019 <Term><Option>-recomp</Option></Term>
1020 <IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
1021 <ListItem>
1022 <Para>
1023 (On by default) Turn on recompilation checking.  This will stop
1024 compilation early, leaving an existing <filename>.o</filename> file in
1025 place, if it can be determined that the module does not need to be
1026 recompiled.
1027 </Para>
1028 </ListItem>
1029 </VarListEntry>
1030 <VarListEntry>
1031 <Term><Option>-no-recomp</Option></Term>
1032 <IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
1033 <ListItem>
1034 <Para>
1035 Turn off recompilation checking.
1036 </Para>
1037 </ListItem>
1038 </VarListEntry>
1039 </VariableList>
1040 </Para>
1041
1042 <Para>
1043 In the olden days, GHC compared the newly-generated
1044 <Filename>.hi</Filename> file with the previous version; if they were
1045 identical, it left the old one alone and didn't change its
1046 modification date.  In consequence, importers of a module with an
1047 unchanged output <Filename>.hi</Filename> file were not recompiled.
1048 </Para>
1049
1050 <Para>
1051 This doesn't work any more.  In our earlier example, module
1052 <Literal>C</Literal> does not import module <Literal>A</Literal>
1053 directly, yet changes to <Filename>A.hi</Filename> should force a
1054 recompilation of <Literal>C</Literal>.  And some changes to
1055 <Literal>A</Literal> (changing the definition of a function that
1056 appears in an inlining of a function exported by <Literal>B</Literal>,
1057 say) may conceivably not change <Filename>B.hi</Filename> one jot.  So
1058 now&hellip;
1059 </Para>
1060
1061 <Para>
1062 GHC keeps a version number on each interface file, and on each type
1063 signature within the interface file.  It also keeps in every interface
1064 file a list of the version numbers of everything it used when it last
1065 compiled the file.  If the source file's modification date is earlier
1066 than the <Filename>.o</Filename> file's date (i.e. the source hasn't
1067 changed since the file was last compiled), and the
1068 <option>-recomp</option> is given on the command line, GHC will be
1069 clever.  It compares the version numbers on the things it needs this
1070 time with the version numbers on the things it needed last time
1071 (gleaned from the interface file of the module being compiled); if
1072 they are all the same it stops compiling rather early in the process
1073 saying &ldquo;Compilation IS NOT required&rdquo;.  What a beautiful
1074 sight!
1075 </Para>
1076
1077 <Para>
1078 Patrick Sansom had a workshop paper about how all this is done (though
1079 the details have changed quite a bit). <ULink URL="mailto:sansom@dcs.gla.ac.uk">Ask him</ULink> if you want a copy.
1080 </Para>
1081
1082 </Sect2>
1083
1084
1085 <Sect2 id="using-make">
1086 <Title>Using <Command>make</Command>
1087 </Title>
1088
1089 <Para>
1090 <IndexTerm><Primary><literal>make</literal></Primary></IndexTerm>
1091 </Para>
1092
1093 <Para>
1094 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.
1095 Thus:
1096 </Para>
1097
1098 <Para>
1099
1100 <ProgramListing>
1101 HC      = ghc
1102 HC_OPTS = -cpp $(EXTRA_HC_OPTS)
1103
1104 SRCS = Main.lhs Foo.lhs Bar.lhs
1105 OBJS = Main.o   Foo.o   Bar.o
1106
1107 .SUFFIXES : .o .hs .hi .lhs .hc .s
1108
1109 cool_pgm : $(OBJS)
1110         rm $@
1111         $(HC) -o $@ $(HC_OPTS) $(OBJS)
1112
1113 # Standard suffix rules
1114 .o.hi:
1115         @:
1116
1117 .lhs.o:
1118         $(HC) -c $&#60; $(HC_OPTS)
1119
1120 .hs.o:
1121         $(HC) -c $&#60; $(HC_OPTS)
1122
1123 # Inter-module dependencies
1124 Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
1125 Main.o Main.hc Main.s : Foo.hi Baz.hi   # Main imports Foo and Baz
1126 </ProgramListing>
1127
1128 </Para>
1129
1130 <Para>
1131 (Sophisticated <Command>make</Command> variants may achieve some of the above more
1132 elegantly.  Notably, <Command>gmake</Command>'s pattern rules let you write the more
1133 comprehensible:
1134 </Para>
1135
1136 <Para>
1137
1138 <ProgramListing>
1139 %.o : %.lhs
1140         $(HC) -c $&#60; $(HC_OPTS)
1141 </ProgramListing>
1142
1143 </Para>
1144
1145 <Para>
1146 What we've shown should work with any <Command>make</Command>.)
1147 </Para>
1148
1149 <Para>
1150 Note the cheesy <Literal>.o.hi</Literal> rule: It records the dependency of the
1151 interface (<Filename>.hi</Filename>) file on the source.  The rule says a <Filename>.hi</Filename> file can
1152 be made from a <Filename>.o</Filename> file by doing&hellip;nothing.  Which is true.
1153 </Para>
1154
1155 <Para>
1156 Note the inter-module dependencies at the end of the Makefile, which
1157 take the form
1158 </Para>
1159
1160 <Para>
1161
1162 <ProgramListing>
1163 Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
1164 </ProgramListing>
1165
1166 </Para>
1167
1168 <Para>
1169 They tell <Command>make</Command> that if any of <Literal>Foo.o</Literal>, <Literal>Foo.hc</Literal> or <Literal>Foo.s</Literal> have an
1170 earlier modification date than <Literal>Baz.hi</Literal>, then the out-of-date file
1171 must be brought up to date.  To bring it up to date, <Literal>make</Literal> looks for
1172 a rule to do so; one of the preceding suffix rules does the job
1173 nicely.
1174 </Para>
1175
1176     </sect2>
1177
1178     <sect2 id="sec-makefile-dependencies">
1179       <title>Dependency generation</title>
1180       <indexterm><primary>dependencies in Makefiles</primary></indexterm>
1181       <indexterm><primary>Makefile dependencies</primary></indexterm>
1182
1183       <para>Putting inter-dependencies of the form <Literal>Foo.o :
1184       Bar.hi</Literal> into your <Filename>Makefile</Filename> by hand
1185       is rather error-prone.  Don't worry, GHC has support for
1186       automatically generating the required dependencies.  Add the
1187       following to your <Filename>Makefile</Filename>:</para>
1188
1189 <ProgramListing>
1190 depend :
1191         ghc -M $(HC_OPTS) $(SRCS)
1192 </ProgramListing>
1193
1194       <para>Now, before you start compiling, and any time you change
1195       the <Literal>imports</Literal> in your program, do <Command>make
1196       depend</Command> before you do <Command>make
1197       cool&lowbar;pgm</Command>.  <Command>ghc -M</Command> will append
1198       the needed dependencies to your
1199       <Filename>Makefile</Filename>.</Para>
1200
1201       <para>In general, if module <Literal>A</Literal> contains the
1202       line
1203
1204 <programlisting>
1205 import B ...blah...
1206 </programlisting>
1207
1208        then <command>ghc -M</command> will generate a dependency
1209        line of the form:
1210
1211 <programlisting>
1212 A.o : B.hi
1213 </programlisting>
1214
1215        If module <literal>A</literal> contains the line 
1216
1217 <programlisting>
1218 import {-# SOURCE #-} B ...blah...
1219 </programlisting>
1220
1221        then <command>ghc -M</command> will generate a dependency
1222        line of the form:
1223
1224 <programlisting>
1225 A.o : B.hi-boot
1226 </programlisting>
1227
1228        (See <xref linkend="hi-files"> for details of interface files.)
1229        If <literal>A</literal> imports multiple modules, then there
1230        will be multiple lines with <filename>A.o</filename> as the
1231        target.</para>
1232
1233       <para>By default, <Command>ghc -M</Command> generates all the
1234       dependencies, and then concatenates them onto the end of
1235       <Filename>makefile</Filename> (or <Filename>Makefile</Filename>
1236       if <Filename>makefile</Filename> doesn't exist) bracketed by the
1237       lines "<Literal>&num; DO NOT DELETE: Beginning of Haskell
1238       dependencies</Literal>" and "<Literal>&num; DO NOT DELETE: End
1239       of Haskell dependencies</Literal>".  If these lines already
1240       exist in the <Filename>makefile</Filename>, then the old
1241       dependencies are deleted first.</para>
1242
1243       <para>Internally, GHC uses a script to generate the
1244       dependencies, called <command>mkdependHS</command>.  This script
1245       has some options of its own, which you might find useful.
1246       Options can be passed directly to <command>mkdependHS</command>
1247       with GHC's <literal>-optdep</literal> option.  For example, to
1248       generate the dependencies into a file called
1249       <literal>.depend</literal> instead of
1250       <literal>Makefile</literal>:</para>
1251
1252 <screen>
1253 ghc -M -optdep-f optdep.depend ...
1254 </screen>
1255       
1256       <para>The full list of options accepted by
1257       <command>mkdependHS</command> is:</para>
1258
1259       <variablelist>
1260
1261         <varlistentry>
1262           <term><option>-w</option></term>
1263           <listitem>
1264             <para>Turn off warnings about interface file shadowing.</para>
1265           </listitem>
1266         </varlistentry>
1267
1268         <varlistentry>
1269           <term><option>-f blah</option></term>
1270           <listitem>
1271             <para>Use <Filename>blah</Filename> as the makefile,
1272             rather than <Filename>makefile</Filename> or
1273             <Filename>Makefile</Filename>.  If
1274             <Filename>blah</Filename> doesn't exist,
1275             <Command>mkdependHS</Command> creates it.  We often use
1276             <Option>-f .depend</Option> to put the dependencies in
1277             <Filename>.depend</Filename> and then
1278             <Command>include</Command> the file
1279             <Filename>.depend</Filename> into
1280             <Filename>Makefile</Filename>.</para>
1281           </listitem>
1282         </varlistentry>
1283
1284         <varlistentry>
1285           <term><option>-o &lt;osuf&gt;</option></term>
1286           <listitem>
1287             <para>Use <Filename>.&lt;osuf&gt;</Filename> as the
1288             "target file" suffix ( default: <Literal>o</Literal>).
1289             Multiple <Option>-o</Option> flags are permitted (GHC2.05
1290             onwards).  Thus "<Option>-o hc -o o</Option>" will
1291             generate dependencies for <Filename>.hc</Filename> and
1292             <Filename>.o</Filename> files.</para>
1293           </listitem>
1294         </varlistentry>
1295
1296         <varlistentry>
1297           <term><option>-s &lt;suf&gt;</option></term>
1298           <listitem>
1299             <para>Make extra dependencies that declare that files with
1300             suffix
1301             <Filename>.&lt;suf&gt;&lowbar;&lt;osuf&gt;</Filename>
1302             depend on interface files with suffix
1303             <Filename>.&lt;suf&gt;&lowbar;hi</Filename>, or (for
1304             <Literal>&lcub;-&num; SOURCE &num;-&rcub;</Literal>
1305             imports) on <Filename>.hi-boot</Filename>.  Multiple
1306             <Option>-s</Option> flags are permitted.  For example,
1307             <Option>-o hc -s a -s b</Option> will make dependencies
1308             for <Filename>.hc</Filename> on <Filename>.hi</Filename>,
1309             <Filename>.a&lowbar;hc</Filename> on
1310             <Filename>.a&lowbar;hi</Filename>, and
1311             <Filename>.b&lowbar;hc</Filename> on
1312             <Filename>.b&lowbar;hi</Filename>.  (Useful in conjunction
1313             with NoFib "ways".)</para>
1314           </listitem>
1315         </varlistentry>
1316
1317         <varlistentry>
1318           <term><option>--exclude-module=&lt;file&gt;</option></term>
1319           <listitem>
1320             <para>Regard <Filename>&lt;file&gt;</Filename> as
1321             "stable"; i.e., exclude it from having dependencies on
1322             it.</para>
1323           </listitem>
1324         </varlistentry>
1325
1326         <varlistentry>
1327           <term><option>-x</option></term>
1328           <listitem>
1329             <para>same as <option>--exclude-module</option></para>
1330           </listitem>
1331         </varlistentry>
1332
1333         <varlistentry>
1334           <term><option>--exclude-directory=&lt;dirs&gt;</option></term>
1335           <listitem>
1336             <para>Regard the colon-separated list of directories
1337             <Filename>&lt;dirs&gt;</Filename> as containing stable,
1338             don't generate any dependencies on modules therein.</para>
1339           </listitem>
1340         </varlistentry>
1341
1342         <varlistentry>
1343           <term><option>-xdirs</option></term>
1344           <listitem>
1345             <para>same as <Option>--exclude-directory</Option>.</para>
1346           </listitem>
1347         </varlistentry>
1348
1349         <varlistentry>
1350           <term><option>--include-module=&lt;file&gt;</option></term>
1351           <listitem>
1352             <para>Regard <Filename>&lt;file&gt;</Filename> as not
1353             "stable"; i.e., generate dependencies on it (if any). This
1354             option is normally used in conjunction with the
1355             <Option>--exclude-directory</Option> option.</para>
1356           </listitem>
1357         </varlistentry>
1358
1359         <varlistentry>
1360           <term><option>--include-prelude</option></term>
1361           <listitem>
1362             <para>Regard prelude libraries as unstable, i.e., generate
1363             dependencies on the prelude modules used (including
1364             <Literal>Prelude</Literal>).  This option is normally only
1365             used by the various system libraries. If a
1366             <Option>-package</Option> option is used, dependencies will
1367             also be generated on the library's interfaces.</para>
1368           </listitem>
1369         </varlistentry>
1370       </variablelist>
1371
1372 </Sect2>
1373
1374 <Sect2 id="mutual-recursion">
1375 <Title>How to compile mutually recursive modules
1376 </Title>
1377
1378 <Para>
1379 <IndexTerm><Primary>module system, recursion</Primary></IndexTerm>
1380 <IndexTerm><Primary>recursion, between modules</Primary></IndexTerm>
1381 </Para>
1382
1383 <Para>
1384 Currently, the compiler does not have proper support for dealing with
1385 mutually recursive modules:
1386 </Para>
1387
1388 <Para>
1389
1390 <ProgramListing>
1391 module A where
1392
1393 import B
1394
1395 newtype TA = MkTA Int
1396
1397 f :: TB -&#62; TA
1398 f (MkTB x) = MkTA x
1399 --------
1400 module B where
1401
1402 import A
1403
1404 data TB = MkTB !Int
1405
1406 g :: TA -&#62; TB
1407 g (MkTA x) = MkTB x
1408 </ProgramListing>
1409
1410 </Para>
1411
1412 <Para>
1413 When compiling either module A and B, the compiler will try (in vain)
1414 to look for the interface file of the other. So, to get mutually
1415 recursive modules off the ground, you need to hand write an interface
1416 file for A or B, so as to break the loop.  These hand-written
1417 interface files are called <Literal>hi-boot</Literal> files, and are placed in a file
1418 called <Filename>&lt;module&gt;.hi-boot</Filename>.  To import from an <Literal>hi-boot</Literal> file instead
1419 of the standard <Filename>.hi</Filename> file, use the following syntax in the importing module:
1420 <IndexTerm><Primary>hi-boot files</Primary></IndexTerm>
1421 <IndexTerm><Primary>importing, hi-boot files</Primary></IndexTerm>
1422 </Para>
1423
1424 <Para>
1425
1426 <ProgramListing>
1427 import {-# SOURCE #-} A
1428 </ProgramListing>
1429
1430 </Para>
1431
1432 <Para>
1433 The hand-written interface need only contain the bare minimum of
1434 information needed to get the bootstrapping process started.  For
1435 example, it doesn't need to contain declarations for <Emphasis>everything</Emphasis>
1436 that module <Literal>A</Literal> exports, only the things required by the module that
1437 imports <Literal>A</Literal> recursively.
1438 </Para>
1439
1440 <Para>
1441 For the example at hand, the boot interface file for A would look like
1442 the following:
1443 </Para>
1444
1445 <Para>
1446
1447 <ProgramListing>
1448 __interface A 1 404 where
1449 __export A TA{MkTA} ;
1450 1 newtype TA = MkTA PrelBase.Int ;
1451 </ProgramListing>
1452
1453 </Para>
1454
1455 <Para>
1456 The syntax is essentially the same as a normal <Filename>.hi</Filename> file
1457 (unfortunately), but you can usually tailor an existing <Filename>.hi</Filename> file to
1458 make a <Filename>.hi-boot</Filename> file.
1459 </Para>
1460
1461 <Para>
1462 Notice that we only put the declaration for the newtype <Literal>TA</Literal> in the
1463 <Literal>hi-boot</Literal> file, not the signature for <Function>f</Function>, since <Function>f</Function> isn't used by
1464 <Literal>B</Literal>.
1465 </Para>
1466
1467 <Para>
1468 The number &ldquo;1&rdquo; after &ldquo;&lowbar;&lowbar;interface A&rdquo; gives the version number of module A;
1469 it is incremented whenever anything in A's interface file changes.  The &ldquo;404&rdquo; is
1470 the version number of the interface file <Emphasis>syntax</Emphasis>; we change it when
1471 we change the syntax of interface files so that you get a better error message when
1472 you try to read an old-format file with a new-format compiler.
1473 </Para>
1474
1475 <Para>
1476 The number &ldquo;1&rdquo; at the beginning of a declaration is the <Emphasis>version
1477 number</Emphasis> of that declaration: for the purposes of <Filename>.hi-boot</Filename> files
1478 these can all be set to 1.  All names must be fully qualified with the
1479 <Emphasis>original</Emphasis> module that an object comes from: for example, the
1480 reference to <Literal>Int</Literal> in the interface for <Literal>A</Literal> comes from <Literal>PrelBase</Literal>,
1481 which is a module internal to GHC's prelude.  It's a pain, but that's
1482 the way it is.
1483 </Para>
1484
1485 <Para>
1486 If you want an hi-boot file to export a data type, but you don't want to give its constructors
1487 (because the constructors aren't used by the SOURCE-importing module), you can write simply:
1488 </Para>
1489
1490 <Para>
1491
1492 <ProgramListing>
1493 __interface A 1 404 where
1494 __export A TA;
1495 1 data TA
1496 </ProgramListing>
1497
1498 </Para>
1499
1500 <Para>
1501 (You must write all the type parameters, but leave out the '=' and everything that follows it.)
1502 </Para>
1503
1504 <Para>
1505 <Emphasis>Note:</Emphasis> This is all a temporary solution, a version of the
1506 compiler that handles mutually recursive modules properly without the manual
1507 construction of interface files, is (allegedly) in the works.
1508 </Para>
1509
1510 </Sect2>
1511
1512 </Sect1>
1513
1514   <sect1 id="packages">
1515     <title>Packages</title>
1516     <indexterm><primary>packages</primary></indexterm>
1517
1518     <para>Packages are collections of libraries, conveniently grouped
1519     together as a single entity.  The package system is flexible: a
1520     package may consist of Haskell code, foreign language code (eg. C
1521     libraries), or a mixture of the two.  A package is a good way to
1522     group together related Haskell modules, and is essential if you
1523     intend to make the modules into a Windows DLL (see below).</para>
1524
1525     <para>Because packages can contain both Haskell and C libraries, they
1526     are also a good way to provide convenient access to a Haskell
1527     layer over a C library.</para>
1528
1529     <para>GHC comes with several packages (see <xref
1530     linkend="book-hslibs">), and packages can be added/removed from an
1531     existing GHC installation.</para>
1532
1533     <sect2 id="listing-packages">
1534       <title>Listing the available packages</title>
1535       <indexterm><primary>packages</primary>
1536         <secondary>listing</secondary></indexterm>
1537
1538       <para>To see what packages are currently installed, use the
1539       <literal>--list-packages</literal> option:</para>
1540       <indexterm><primary><literal>--list-packages</literal></primary>
1541       </indexterm>
1542
1543 <screen>
1544   $ ghc --list-packages
1545   gmp, rts, std, lang, concurrent, data, net, posix, text, util
1546 </screen>
1547
1548       <para>Note that your GHC installation might have a slightly
1549       different set of packages installed.</para>
1550
1551       <para>The <literal>gmp</literal> and <literal>rts</literal>
1552       packages are always present, and represent the multi-precision
1553       integer and runtime system libraries respectively.  The
1554       <literal>std</literal> package contains the Haskell prelude.
1555       The rest of the packages are optional libraries.</para>
1556
1557     </sect2>
1558
1559     <sect2 id="using-packages">
1560       <title>Using a package</title>
1561       <indexterm><primary>packages</primary>
1562         <secondary>using</secondary></indexterm>
1563       
1564       <para>To use a package, add the <literal>-package</literal> flag
1565       to the command line:</para>
1566
1567       <variablelist>
1568         <varlistentry>
1569           <term><option>-package &lt;lib&gt;</option></term>
1570           <indexterm><primary>-package &lt;lib&gt; option</primary></indexterm>
1571           <listitem>
1572             <para>This option brings into scope all the modules from
1573             package <literal>&lt;lib&gt;</literal> (they still have to
1574             be imported in your Haskell source, however).  It also
1575             causes the relevant libraries to be linked when linking is
1576             being done.</para>
1577           </listitem>
1578         </varlistentry>
1579       </variablelist>
1580
1581       <para>Some packages depend on other packages, for example the
1582       <literal>text</literal> package makes use of some of the modules
1583       in the <literal>lang</literal> package.  The package system
1584       takes care of all these dependencies, so that when you say
1585       <literal>-package text</literal> on the command line, you
1586       automatically get <literal>-package lang</literal> too.</para>
1587     </sect2>
1588
1589     <sect2 id="building-packages">
1590       <title>Building a package from Haskell source</title>
1591       <indexterm><primary>packages</primary>
1592         <secondary>building</secondary></indexterm>
1593
1594       <para>It takes some special considerations to build a new
1595       package:</para>
1596
1597       <itemizedlist>
1598         <listitem>
1599           <para>A package may contain several Haskell modules. A
1600           package may span many directories, or many packages may
1601           exist in a single directory. Packages may not be mutually
1602           recursive.</para>
1603         </listitem>
1604
1605         <listitem>
1606           <para>A package has a name
1607           (e.g. <filename>std</filename>)</para>
1608         </listitem>
1609
1610         <listitem>
1611           <para>The Haskell code in a package may be built into one or
1612           more Unix libraries (e.g. <Filename>libHSfoo.a</Filename>),
1613           or a single DLL on Windows
1614           (e.g. <Filename>HSfoo.dll</Filename>).  The restriction to a
1615           single DLL on Windows is that the package system is used to
1616           tell the compiler when it should make an inter-DLL call
1617           rather than an intra-DLL call (inter-DLL calls require an
1618           extra indirection).</para>
1619         </listitem>
1620
1621         <listitem>
1622           <para>GHC does not maintain detailed cross-package
1623           dependency information.  It does remember which modules in
1624           other packages the current module depends on, but not which
1625           things within those imported things.</para>
1626         </listitem>
1627       </itemizedlist>
1628
1629       <para>To compile a module which is to be part of a new package,
1630       use the <literal>-package-name</literal> option:</para>
1631
1632       <variablelist>
1633         <varlistentry>
1634           <term><option>-package-name &lt;foo&gt;</option></term>
1635           <indexterm><primary><literal>-package-name</literal></primary>
1636             <secondary>option</secondary></indexterm>
1637           <listitem>
1638             <para>This option is added to the command line when
1639             compiling a module that is destined to be part of package
1640             <literal>foo</literal>.  If this flag is omitted then the
1641             default package <literal>Main</literal> is assumed.</para>
1642           </listitem>
1643         </varlistentry>
1644       </variablelist>
1645
1646       <para>Failure to use the <literal>-package-name</literal> option
1647       when compiling a package will result in disaster on Windows, but
1648       is relatively harmless on Unix at the moment (it will just cause
1649       a few extra dependencies in some interface files).  However,
1650       bear in mind that we might add support for Unix shared libraries
1651       at some point in the future.</para>
1652
1653       <para>It is worth noting that on Windows, because each package
1654       is built as a DLL, and a reference to a DLL costs an extra
1655       indirection, intra-package references are cheaper than
1656       inter-package references. Of course, this applies to the
1657       <Filename>Main</Filename> package as well.</para>
1658
1659     </sect2>
1660     <sect2 id="package-management">
1661       <title>Package management</title>
1662       <indexterm><primary>packages</primary>
1663         <secondary>management</secondary></indexterm>
1664       
1665       <para>GHC uses a package configuration file, called
1666       <literal>packages.conf</literal>, which can be found in your GHC
1667       install directory.  This file isn't intended to be edited
1668       directly, instead GHC provides options for adding & removing
1669       packages:</para>
1670
1671       <variablelist>
1672         <varlistentry>
1673           <term><option>--add-package</option></term>
1674           <indexterm><primary><literal>--add-package</literal></primary>
1675               <secondary>option</secondary></indexterm>
1676           <listitem>
1677             <para>Reads a package specification (see below) on stdin,
1678             and adds it to the database of installed packages.  The
1679             package specification must be a package that isn't already
1680             installed.</para>
1681           </listitem>
1682         </varlistentry>
1683
1684         <varlistentry>
1685           <term><option>--delete-package &lt;foo&gt;</option></term>
1686           <indexterm><primary><literal>--delete-package</literal></primary>
1687               <secondary>option</secondary></indexterm>
1688           <listitem>
1689             <para>Removes the specified package from the installed
1690             configuration.</para>
1691           </listitem>
1692         </varlistentry>
1693       </variablelist>
1694
1695       <para>In both cases, the old package configuration file is saved
1696       in <literal>packages.conf.old</literal> in your GHC install
1697       directory, so in an emergency you can always copy this file into
1698       <literal>package.conf</literal> to restore the old
1699       settings.</para>
1700
1701       <para>A package specification looks like this:</para>
1702
1703 <screen>
1704   Package {
1705      name            = "mypkg",
1706      import_dirs     = ["/usr/local/lib/imports/mypkg"],
1707      library_dirs    = ["/usr/local/lib"],
1708      hs_libraries    = ["HSmypkg" ],
1709      extra_libraries = ["HSmypkg_cbits"],
1710      include_dirs    = [],
1711      c_includes      = ["HsMyPkg.h"],
1712      package_deps    = ["text", "data"],
1713      extra_ghc_opts  = [],
1714      extra_cc_opts   = [],
1715      extra_ld_opts   = ["-lmy_clib"]
1716   }
1717 </screen>
1718
1719       <para>Components of a package specification may be specified in
1720       any order, and are:</para>
1721
1722       <variablelist>
1723         <varlistentry>
1724           <term><literal>name</literal></term>
1725           <indexterm><primary><literal>name</literal></primary>
1726             <secondary>package specification</secondary></indexterm>
1727           <listitem>
1728             <para>The package's name, for use with
1729             the <literal>-package</literal> flag and as listed in the
1730             <literal>--list-packages</literal> list. 
1731             </para>
1732           </listitem>
1733         </varlistentry>
1734
1735         <varlistentry>
1736           <term><literal>import_dirs</literal></term>
1737           <indexterm><primary><literal>import_dirs</literal></primary>
1738             <secondary>package specification</secondary></indexterm>
1739           <listitem>
1740             <para>A list of directories containing interface files
1741             (<literal>.hi</literal> files) for this package.</para>
1742           </listitem>
1743         </varlistentry>
1744
1745         <varlistentry>
1746           <term><literal>library_dirs</literal></term>
1747           <indexterm><primary><literal>library_dirs</literal></primary>
1748             <secondary>package specification</secondary></indexterm>
1749           <listitem>
1750             <para>A list of directories containing libraries for this
1751             package.</para>
1752           </listitem>
1753         </varlistentry>
1754
1755         <varlistentry>
1756           <term><literal>hs_libraries</literal></term>
1757           <indexterm><primary><literal>hs_libraries</literal></primary>
1758             <secondary>package specification</secondary></indexterm>
1759           <listitem>
1760             <para>A list of libraries containing Haskell code for this
1761             package, with the <literal>.a</literal> or
1762             <literal>.dll</literal> suffix omitted.  On Unix, the
1763             <literal>lib</literal> prefix is also omitted.</para>
1764           </listitem>
1765         </varlistentry>
1766
1767         <varlistentry>
1768           <term><literal>extra_libraries</literal></term>
1769           <indexterm><primary><literal>extra_libraries</literal></primary>
1770             <secondary>package specification</secondary></indexterm>
1771           <listitem>
1772             <para>A list of extra libraries for this package.  The
1773             difference between <literal>hs_libraries</literal> and
1774             <literal>extra_libraries</literal> is that
1775             <literal>hs_libraries</literal> normally have several
1776             versions, to support profiling, parallel and other build
1777             options.  The various versions are given different
1778             suffixes to distinguish them, for example the profiling
1779             version of the standard prelude library is named
1780             <filename>libHSstd_p.a</filename>, with the
1781             <literal>_p</literal> indicating that this is a profiling
1782             version.  The suffix is added automatically by GHC for
1783             <literal>hs_libraries</literal> only, no suffix is added
1784             for libraries in
1785             <literal>extra_libraries</literal>.</para>
1786
1787             <para>Also, <literal>extra_libraries</literal> are placed
1788             on the linker command line before the
1789             <literal>hs_libraries</literal> for the same package.  If
1790             your package has dependencies in the other direction, you
1791             might need to make two separate packages.</para>
1792           </listitem>
1793         </varlistentry>
1794
1795         <varlistentry>
1796           <term><literal>include_dirs</literal></term>
1797           <indexterm><primary><literal>include_dirs</literal></primary>
1798             <secondary>package specification</secondary></indexterm>
1799           <listitem>
1800             <para>A list of directories containing C includes for this
1801             package (maybe the empty list).</para>
1802           </listitem>
1803         </varlistentry>
1804
1805         <varlistentry>
1806           <term><literal>c_includes</literal></term>
1807           <indexterm><primary><literal>c_includes</literal></primary>
1808             <secondary>package specification</secondary></indexterm>
1809           <listitem>
1810             <para>A list of files to include for via-C compilations
1811             using this package.  Typically this include file will
1812             contain function prototypes for any C functions used in
1813             the package, in case they end up being called as a result
1814             of Haskell functions from the package being
1815             inlined.</para>
1816           </listitem>
1817         </varlistentry>
1818
1819         <varlistentry>
1820           <term><literal>package_deps</literal></term>
1821           <indexterm><primary><literal>package_deps</literal></primary>
1822             <secondary>package specification</secondary></indexterm>
1823           <listitem>
1824             <para>A list of packages which this package depends
1825             on.</para>
1826           </listitem>
1827         </varlistentry>
1828
1829         <varlistentry>
1830           <term><literal>extra_ghc_opts</literal></term>
1831           <indexterm><primary><literal>extra_ghc_opts</literal></primary>
1832             <secondary>package specification</secondary></indexterm>
1833           <listitem>
1834             <para>Extra arguments to be added to the GHC command line
1835             when this package is being used.</para>
1836           </listitem>
1837         </varlistentry>
1838
1839         <varlistentry>
1840           <term><literal>extra_cc_opts</literal></term>
1841           <indexterm><primary><literal>extra_cc_opts</literal></primary>
1842             <secondary>package specification</secondary></indexterm>
1843           <listitem>
1844             <para>Extra arguments to be added to the gcc command line
1845             when this package is being used (only for via-C
1846             compilations).</para>
1847           </listitem>
1848         </varlistentry>
1849
1850         <varlistentry>
1851           <term><literal>extra_ld_opts</literal></term>
1852           <indexterm><primary><literal>extra_ld_opts</literal></primary>
1853             <secondary>package specification</secondary></indexterm>
1854           <listitem>
1855             <para>Extra arguments to be added to the gcc command line
1856             (for linking) when this package is being used.</para>
1857           </listitem>
1858         </varlistentry>
1859       </variablelist>
1860
1861       <para>For examples of more package specifications, take a look
1862       at the <literal>package.conf</literal> in your GHC
1863       installation.</para>
1864     </sect2>
1865   </sect1>
1866
1867
1868 <Sect1 id="options-optimise">
1869 <Title>Optimisation (code improvement)
1870 </Title>
1871
1872 <Para>
1873 <IndexTerm><Primary>optimisation (GHC)</Primary></IndexTerm>
1874 <IndexTerm><Primary>improvement, code (GHC)</Primary></IndexTerm>
1875 </Para>
1876
1877 <Para>
1878 The <Option>-O*</Option> options specify convenient &ldquo;packages&rdquo; of optimisation
1879 flags; the <Option>-f*</Option> options described later on specify
1880 <Emphasis>individual</Emphasis> optimisations to be turned on/off; the <Option>-m*</Option>
1881 options specify <Emphasis>machine-specific</Emphasis> optimisations to be turned
1882 on/off.
1883 </Para>
1884
1885 <Sect2 id="optimise-pkgs">
1886 <Title><Option>-O*</Option>: convenient &ldquo;packages&rdquo; of optimisation flags.
1887 </Title>
1888
1889 <Para>
1890 <IndexTerm><Primary>-O options</Primary></IndexTerm>
1891 </Para>
1892
1893 <Para>
1894 There are <Emphasis>many</Emphasis> options that affect the quality of code
1895 produced by GHC.  Most people only have a general goal, something like
1896 &ldquo;Compile quickly&rdquo; or &ldquo;Make my program run like greased lightning.&rdquo;
1897 The following &ldquo;packages&rdquo; of optimisations (or lack thereof) should
1898 suffice.
1899 </Para>
1900
1901 <Para>
1902 Once you choose a <Option>-O*</Option> &ldquo;package,&rdquo; stick with it&mdash;don't chop and
1903 change.  Modules' interfaces <Emphasis>will</Emphasis> change with a shift to a new
1904 <Option>-O*</Option> option, and you may have to recompile a large chunk of all
1905 importing modules before your program can again be run
1906 safely (see <XRef LinkEnd="recomp">).
1907 </Para>
1908
1909 <Para>
1910 <VariableList>
1911
1912 <VarListEntry>
1913 <Term>No <Option>-O*</Option>-type option specified:</Term>
1914 <IndexTerm><Primary>-O* not specified</Primary></IndexTerm>
1915 <ListItem>
1916 <Para>
1917 This is taken to mean: &ldquo;Please compile quickly; I'm not over-bothered
1918 about compiled-code quality.&rdquo;  So, for example: <Command>ghc -c Foo.hs</Command>
1919 </Para>
1920 </ListItem>
1921 </VarListEntry>
1922 <VarListEntry>
1923 <Term><Option>-O</Option> or <Option>-O1</Option>:</Term>
1924 <IndexTerm><Primary>-O option</Primary></IndexTerm>
1925 <IndexTerm><Primary>-O1 option</Primary></IndexTerm>
1926 <IndexTerm><Primary>optimise</Primary><secondary>normally</secondary></IndexTerm>
1927 <ListItem>
1928 <Para>
1929 Means: &ldquo;Generate good-quality code without taking too long about
1930 it.&rdquo; Thus, for example: <Command>ghc -c -O Main.lhs</Command>
1931 </Para>
1932 </ListItem>
1933 </VarListEntry>
1934 <VarListEntry>
1935 <Term><Option>-O2</Option>:</Term>
1936 <IndexTerm><Primary>-O2 option</Primary></IndexTerm>
1937 <IndexTerm><Primary>optimise</Primary><secondary>aggressively</secondary></IndexTerm>
1938 <ListItem>
1939 <Para>
1940 Means: &ldquo;Apply every non-dangerous optimisation, even if it means
1941 significantly longer compile times.&rdquo;
1942 </Para>
1943
1944 <Para>
1945 The avoided &ldquo;dangerous&rdquo; optimisations are those that can make
1946 runtime or space <Emphasis>worse</Emphasis> if you're unlucky.  They are
1947 normally turned on or off individually.
1948 </Para>
1949
1950 <Para>
1951 At the moment, <Option>-O2</Option> is <Emphasis>unlikely</Emphasis> to produce
1952 better code than <Option>-O</Option>.
1953 </Para>
1954 </ListItem>
1955 </VarListEntry>
1956 <VarListEntry>
1957 <Term><Option>-O2-for-C</Option>:</Term>
1958 <IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm>
1959 <IndexTerm><Primary>gcc, invoking with -O2</Primary></IndexTerm>
1960 <ListItem>
1961 <Para>
1962 Says to run GCC with <Option>-O2</Option>, which may be worth a few percent in
1963 execution speed.  Don't forget <Option>-fvia-C</Option>, lest you use the native-code
1964 generator and bypass GCC altogether!
1965 </Para>
1966 </ListItem>
1967 </VarListEntry>
1968 <VarListEntry>
1969 <Term><Option>-Onot</Option>:</Term>
1970 <IndexTerm><Primary>-Onot option</Primary></IndexTerm>
1971 <IndexTerm><Primary>optimising, reset</Primary></IndexTerm>
1972 <ListItem>
1973 <Para>
1974 This option will make GHC &ldquo;forget&rdquo; any
1975 <Option>-O</Option>ish options it has seen so far.  Sometimes useful;
1976 for example: <Command>make all
1977 EXTRA&lowbar;HC&lowbar;OPTS=-Onot</Command>.
1978 </Para>
1979 </ListItem>
1980 </VarListEntry>
1981 <VarListEntry>
1982 <Term><Option>-Ofile &lt;file&gt;</Option>:</Term>
1983 <IndexTerm><Primary>-Ofile &lt;file&gt; option</Primary></IndexTerm>
1984 <IndexTerm><Primary>optimising, customised</Primary></IndexTerm>
1985 <ListItem>
1986 <Para>
1987 For those who need <Emphasis>absolute</Emphasis> control over
1988 <Emphasis>exactly</Emphasis> what options are used (e.g., compiler
1989 writers, sometimes :-), a list of options can be put in a file and
1990 then slurped in with <Option>-Ofile</Option>.
1991 </Para>
1992
1993 <Para>
1994 In that file, comments are of the
1995 <Literal>&num;</Literal>-to-end-of-line variety; blank lines and most
1996 whitespace is ignored.
1997 </Para>
1998
1999 <Para>
2000 Please ask if you are baffled and would like an example of <Option>-Ofile</Option>!
2001 </Para>
2002 </ListItem>
2003 </VarListEntry>
2004 </VariableList>
2005 </Para>
2006
2007 <Para>
2008 At Glasgow, we don't use a <Option>-O*</Option> flag for day-to-day work.  We use
2009 <Option>-O</Option> to get respectable speed; e.g., when we want to measure
2010 something.  When we want to go for broke, we tend to use <Option>-O -fvia-C
2011 -O2-for-C</Option> (and we go for lots of coffee breaks).
2012 </Para>
2013
2014 <Para>
2015 The easiest way to see what <Option>-O</Option> (etc.) &ldquo;really mean&rdquo; is to run with
2016 <Option>-v</Option>, then stand back in amazement.  Alternatively, just look at the
2017 <Literal>HsC&lowbar;minus&lt;blah&gt;</Literal> lists in the GHC driver script.
2018 </Para>
2019
2020 </Sect2>
2021
2022 <Sect2>
2023 <Title><Option>-f*</Option>: platform-independent flags</Title>
2024
2025 <Para>
2026 <IndexTerm><Primary>-f* options (GHC)</Primary></IndexTerm>
2027 <IndexTerm><Primary>-fno-* options (GHC)</Primary></IndexTerm>
2028 </Para>
2029
2030 <Para>
2031 Flags can be turned <Emphasis>off</Emphasis> individually.  (NB: I hope you have a
2032 good reason for doing this&hellip;) To turn off the <Option>-ffoo</Option> flag, just use
2033 the <Option>-fno-foo</Option> flag.<IndexTerm><Primary>-fno-&lt;opt&gt; anti-option</Primary></IndexTerm> So, for
2034 example, you can say <Option>-O2 -fno-strictness</Option>, which will then drop out
2035 any running of the strictness analyser.
2036 </Para>
2037
2038 <Para>
2039 The options you are most likely to want to turn off are:
2040
2041 <ItemizedList>
2042 <ListItem>
2043
2044 <Para>
2045 <Option>-fno-strictness</Option><IndexTerm><Primary>-fno-strictness option</Primary></IndexTerm> (strictness
2046 analyser, because it is sometimes slow),
2047 </Para>
2048 </ListItem>
2049 <ListItem>
2050
2051 <Para>
2052 <Option>-fno-specialise</Option><IndexTerm><Primary>-fno-specialise option</Primary></IndexTerm> (automatic
2053 specialisation of overloaded functions, because it can make your code
2054 bigger) (US spelling also accepted), and
2055 </Para>
2056 </ListItem>
2057 <ListItem>
2058
2059 <Para>
2060 <Option>-fno-cpr-analyse</Option><IndexTerm><Primary>-fno-cpr-analyse option</Primary></IndexTerm> switches off the CPR (constructed product
2061 result) analyser.
2062 </Para>
2063 </ListItem>
2064
2065 </ItemizedList>
2066
2067 </Para>
2068
2069 <Para>
2070 Should you wish to turn individual flags <Emphasis>on</Emphasis>, you are advised
2071 to use the <Option>-Ofile</Option> option, described above.  Because the order in
2072 which optimisation passes are run is sometimes crucial, it's quite
2073 hard to do with command-line options.
2074 </Para>
2075
2076 <Para>
2077 Here are some &ldquo;dangerous&rdquo; optimisations you <Emphasis>might</Emphasis> want to try:
2078 <VariableList>
2079
2080 <VarListEntry>
2081 <Term><Option>-fvia-C</Option>:</Term>
2082 <ListItem>
2083 <Para>
2084 <IndexTerm><Primary>-fvia-C option</Primary></IndexTerm>
2085 <IndexTerm><Primary>native code generator, turning off</Primary></IndexTerm>
2086 </Para>
2087
2088 <Para>
2089 Compile via C, and don't use the native-code generator.  (There are many
2090 cases when GHC does this on its own.) You might pick up a little bit of
2091 speed by compiling via C (e.g. for floating-point intensive code on Intel).
2092 If you use <Function>&lowbar;casm&lowbar;</Function>s (which are utterly
2093 deprecated), you probably <Emphasis>have</Emphasis> to use
2094 <Option>-fvia-C</Option>.
2095 </Para>
2096
2097 <Para>
2098 The lower-case incantation, <Option>-fvia-c</Option>, is synonymous.
2099 </Para>
2100
2101 <Para>
2102 Compiling via C will probably be slower (in compilation time) than
2103 using GHC's native code generator.
2104 </Para>
2105 </ListItem>
2106 </VarListEntry>
2107 <VarListEntry>
2108 <Term><Option>-funfolding-interface-threshold&lt;n&gt;</Option>:</Term>
2109 <ListItem>
2110 <Para>
2111 <IndexTerm><Primary>-funfolding-interface-threshold option</Primary></IndexTerm>
2112 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
2113 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
2114 (Default: 30) By raising or lowering this number, you can raise or
2115 lower the amount of pragmatic junk that gets spewed into interface
2116 files.  (An unfolding has a &ldquo;size&rdquo; that reflects the cost in terms
2117 of &ldquo;code bloat&rdquo; of expanding that unfolding in another module.  A
2118 bigger function would be assigned a bigger cost.)
2119 </Para>
2120 </ListItem>
2121 </VarListEntry>
2122 <VarListEntry>
2123 <Term><Option>-funfolding-creation-threshold&lt;n&gt;</Option>:</Term>
2124 <ListItem>
2125 <Para>
2126 <IndexTerm><Primary>-funfolding-creation-threshold option</Primary></IndexTerm>
2127 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
2128 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
2129 (Default: 30) This option is similar to
2130 <Option>-funfolding-interface-threshold</Option>, except that it governs unfoldings
2131 within a single module.  Increasing this figure is more likely to
2132 result in longer compile times than faster code.  The next option is
2133 more useful:
2134 </Para>
2135 </ListItem>
2136 </VarListEntry>
2137 <VarListEntry>
2138 <Term><Option>-funfolding-use-threshold&lt;n&gt;</Option>:</Term>
2139 <ListItem>
2140 <Para>
2141 <IndexTerm><Primary>-funfolding-use-threshold option</Primary></IndexTerm>
2142 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
2143 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
2144 (Default: 8) This is the magic cut-off figure for unfolding: below
2145 this size, a function definition will be unfolded at the call-site,
2146 any bigger and it won't.  The size computed for a function depends on
2147 two things: the actual size of the expression minus any discounts that
2148 apply (see <Option>-funfolding-con-discount</Option>).
2149 </Para>
2150 </ListItem>
2151 </VarListEntry>
2152
2153 <VarListEntry>
2154 <Term><Option>-funfolding-update-in-place&lt;n&gt;</Option>:</Term>
2155 <ListItem>
2156 <Para>
2157 Switches on an experimental "optimisation".  Switching it on makes the compiler
2158 a little keener to inline a function that returns a constructor, if the context is
2159 that of a thunk.
2160 <ProgramListing>
2161    x = plusInt a b
2162 </ProgramListing>
2163 If we inlined plusInt we might get an opportunity to use update-in-place for
2164 the thunk 'x'.
2165 </Para>
2166 </ListItem>
2167 </VarListEntry>
2168
2169 <VarListEntry>
2170 <Term><Option>-funbox-strict-fields</Option>:</Term>
2171 <ListItem>
2172 <Para>
2173 <IndexTerm><Primary>-funbox-strict-fields option</Primary></IndexTerm>
2174 <IndexTerm><Primary>strict constructor fields</Primary></IndexTerm>
2175 <IndexTerm><Primary>constructor fields, strict</Primary></IndexTerm>
2176 </Para>
2177
2178 <Para>
2179 This option causes all constructor fields which are marked strict
2180 (i.e. &ldquo;!&rdquo;) to be unboxed or unpacked if possible.  For example:
2181 </Para>
2182
2183 <Para>
2184
2185 <ProgramListing>
2186 data T = T !Float !Float
2187 </ProgramListing>
2188
2189 </Para>
2190
2191 <Para>
2192 will create a constructor <Literal>T</Literal> containing two unboxed floats if the
2193 <Option>-funbox-strict-fields</Option> flag is given.  This may not always be an
2194 optimisation: if the <Function>T</Function> constructor is scrutinised and the floats
2195 passed to a non-strict function for example, they will have to be
2196 reboxed (this is done automatically by the compiler).
2197 </Para>
2198
2199 <Para>
2200 This option should only be used in conjunction with <Option>-O</Option>, in order to
2201 expose unfoldings to the compiler so the reboxing can be removed as
2202 often as possible.  For example:
2203 </Para>
2204
2205 <Para>
2206
2207 <ProgramListing>
2208 f :: T -&#62; Float
2209 f (T f1 f2) = f1 + f2
2210 </ProgramListing>
2211
2212 </Para>
2213
2214 <Para>
2215 The compiler will avoid reboxing <Function>f1</Function> and <Function>f2</Function> by inlining <Function>+</Function> on
2216 floats, but only when <Option>-O</Option> is on.
2217 </Para>
2218
2219 <Para>
2220 Any single-constructor data is eligible for unpacking; for example
2221 </Para>
2222
2223 <Para>
2224
2225 <ProgramListing>
2226 data T = T !(Int,Int)
2227 </ProgramListing>
2228
2229 </Para>
2230
2231 <Para>
2232 will store the two <Literal>Int</Literal>s directly in the <Function>T</Function> constructor, by flattening
2233 the pair.  Multi-level unpacking is also supported:
2234 </Para>
2235
2236 <Para>
2237
2238 <ProgramListing>
2239 data T = T !S
2240 data S = S !Int !Int
2241 </ProgramListing>
2242
2243 </Para>
2244
2245 <Para>
2246 will store two unboxed <Literal>Int&num;</Literal>s directly in the <Function>T</Function> constructor.
2247 </Para>
2248 </ListItem>
2249 </VarListEntry>
2250 <VarListEntry>
2251 <Term><Option>-fsemi-tagging</Option>:</Term>
2252 <ListItem>
2253 <Para>
2254 This option (which <Emphasis>does not work</Emphasis> with the native-code generator)
2255 tells the compiler to add extra code to test for already-evaluated
2256 values.  You win if you have lots of such values during a run of your
2257 program, you lose otherwise.  (And you pay in extra code space.)
2258 </Para>
2259
2260 <Para>
2261 We have not played with <Option>-fsemi-tagging</Option> enough to recommend it.
2262 (For all we know, it doesn't even work anymore&hellip; Sigh.)
2263 </Para>
2264 </ListItem>
2265 </VarListEntry>
2266 <VarListEntry>
2267 <Term><Option>-fexcess-precision</Option>:</Term>
2268 <ListItem>
2269 <Para>
2270 When this option is given, intermediate floating point values can have
2271 a <Emphasis>greater</Emphasis> precision/range than the final type.
2272 Generally this is a good thing, but some programs may rely on the
2273 exact precision/range of <Literal>Float</Literal>/<Literal>Double</Literal>
2274 values and should not use this option for their compilation.
2275 </Para>
2276 </ListItem>
2277 </VarListEntry>
2278 </VariableList>
2279 </Para>
2280
2281 </Sect2>
2282
2283 <Sect2>
2284 <Title><Option>-m*</Option>: platform-specific flags</Title>
2285
2286 <Para>
2287 <IndexTerm><Primary>-m* options (GHC)</Primary></IndexTerm>
2288 <IndexTerm><Primary>platform-specific options</Primary></IndexTerm>
2289 <IndexTerm><Primary>machine-specific options</Primary></IndexTerm>
2290 </Para>
2291
2292 <Para>
2293 Some flags only make sense for particular target platforms.
2294 </Para>
2295
2296 <Para>
2297 <VariableList>
2298
2299 <VarListEntry>
2300 <Term><Option>-mv8</Option>:</Term>
2301 <ListItem>
2302 <Para>
2303 (SPARC machines)<IndexTerm><Primary>-mv8 option (SPARC only)</Primary></IndexTerm>
2304 Means to pass the like-named option to GCC; it says to use the
2305 Version 8 SPARC instructions, notably integer multiply and divide.
2306 The similiar <Option>-m*</Option> GCC options for SPARC also work, actually.
2307 </Para>
2308 </ListItem>
2309 </VarListEntry>
2310 <VarListEntry>
2311 <Term><Option>-mlong-calls</Option>:</Term>
2312 <ListItem>
2313 <Para>
2314 (HPPA machines)<IndexTerm><Primary>-mlong-calls option (HPPA only)</Primary></IndexTerm>
2315 Means to pass the like-named option to GCC.  Required for Very Big
2316 modules, maybe.  (Probably means you're in trouble&hellip;)
2317 </Para>
2318 </ListItem>
2319 </VarListEntry>
2320 <VarListEntry>
2321 <Term><Option>-monly-[32]-regs</Option>:</Term>
2322 <ListItem>
2323 <Para>
2324 (iX86 machines)<IndexTerm><Primary>-monly-N-regs option (iX86 only)</Primary></IndexTerm>
2325 GHC tries to &ldquo;steal&rdquo; four registers from GCC, for performance
2326 reasons; it almost always works.  However, when GCC is compiling some
2327 modules with four stolen registers, it will crash, probably saying:
2328
2329 <Screen>
2330 Foo.hc:533: fixed or forbidden register was spilled.
2331 This may be due to a compiler bug or to impossible asm
2332 statements or clauses.
2333 </Screen>
2334
2335 Just give some registers back with <Option>-monly-N-regs</Option>.  Try `3' first,
2336 then `2'.  If `2' doesn't work, please report the bug to us.
2337 </Para>
2338 </ListItem>
2339 </VarListEntry>
2340 </VariableList>
2341 </Para>
2342
2343 </Sect2>
2344
2345 <Sect2 id="optimise-C-compiler">
2346 <Title>Code improvement by the C compiler.
2347 </Title>
2348
2349 <Para>
2350 <IndexTerm><Primary>optimisation by GCC</Primary></IndexTerm>
2351 <IndexTerm><Primary>GCC optimisation</Primary></IndexTerm>
2352 </Para>
2353
2354 <Para>
2355 The C&nbsp;compiler (GCC) is run with <Option>-O</Option> turned on.  (It has
2356 to be, actually).
2357 </Para>
2358
2359 <Para>
2360 If you want to run GCC with <Option>-O2</Option>&mdash;which may be worth a few
2361 percent in execution speed&mdash;you can give a
2362 <Option>-O2-for-C</Option><IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm> option.
2363 </Para>
2364
2365 </Sect2>
2366
2367 </Sect1>
2368
2369 <Sect1 id="options-phases">
2370 <Title>Options related to a particular phase
2371 </Title>
2372
2373 <Sect2 id="c-pre-processor">
2374 <Title>The C pre-processor
2375 </Title>
2376
2377 <Para>
2378 <IndexTerm><Primary>pre-processing: cpp</Primary></IndexTerm>
2379 <IndexTerm><Primary>C pre-processor options</Primary></IndexTerm>
2380 <IndexTerm><Primary>cpp, pre-processing with</Primary></IndexTerm>
2381 </Para>
2382
2383 <Para>
2384 The C pre-processor <Command>cpp</Command> is run over your Haskell code only if the
2385 <Option>-cpp</Option> option <IndexTerm><Primary>-cpp option</Primary></IndexTerm> is given.  Unless you are
2386 building a large system with significant doses of conditional
2387 compilation, you really shouldn't need it.
2388 <VariableList>
2389
2390 <VarListEntry>
2391 <Term><Option>-D&lt;foo&gt;</Option>:</Term>
2392 <ListItem>
2393 <Para>
2394 <IndexTerm><Primary>-D&lt;name&gt; option</Primary></IndexTerm>
2395 Define macro <Constant>&lt;foo&gt;</Constant> in the usual way.  NB: does <Emphasis>not</Emphasis> affect
2396 <Option>-D</Option> macros passed to the C&nbsp;compiler when compiling via C!  For those,
2397 use the <Option>-optc-Dfoo</Option> hack&hellip; (see <XRef LinkEnd="forcing-options-through">).
2398 </Para>
2399 </ListItem>
2400 </VarListEntry>
2401 <VarListEntry>
2402 <Term><Option>-U&lt;foo&gt;</Option>:</Term>
2403 <ListItem>
2404 <Para>
2405 <IndexTerm><Primary>-U&lt;name&gt; option</Primary></IndexTerm>
2406 Undefine macro <Command>&lt;foo&gt;</Command> in the usual way.
2407 </Para>
2408 </ListItem>
2409 </VarListEntry>
2410 <VarListEntry>
2411 <Term><Option>-I&lt;dir&gt;</Option>:</Term>
2412 <ListItem>
2413 <Para>
2414 <IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
2415 Specify a directory in which to look for <Literal>&num;include</Literal> files, in
2416 the usual C way.
2417 </Para>
2418 </ListItem>
2419 </VarListEntry>
2420 </VariableList>
2421 </Para>
2422
2423 <Para>
2424 The GHC driver pre-defines several macros when processing Haskell
2425 source code (<Filename>.hs</Filename> or <Filename>.lhs</Filename> files):
2426 </Para>
2427
2428 <Para>
2429 <VariableList>
2430
2431 <VarListEntry>
2432 <Term><Constant>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Constant>:</Term>
2433 <ListItem>
2434 <Para>
2435 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Primary></IndexTerm>
2436 If defined, this means that GHC supports the language defined by the
2437 Haskell 98 report.
2438 </Para>
2439 </ListItem>
2440 </VarListEntry>
2441 <VarListEntry>
2442 <Term><Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;=98</Constant>:</Term>
2443 <ListItem>
2444 <Para>
2445 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Primary></IndexTerm>
2446 In GHC 4.04 and later, the <Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Constant> macro is defined as having
2447 the value <Constant>98</Constant>.
2448 </Para>
2449 </ListItem>
2450 </VarListEntry>
2451 <VarListEntry>
2452 <Term><Constant>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar;</Constant>:</Term>
2453 <ListItem>
2454 <Para>
2455 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar; macro</Primary></IndexTerm>
2456 If defined to <Emphasis>n</Emphasis>, that means GHC supports the Haskell language
2457 defined in the Haskell report version <Emphasis>1.n</Emphasis>.  Currently 5.  This
2458 macro is deprecated, and will probably disappear in future versions.
2459 </Para>
2460 </ListItem>
2461 </VarListEntry>
2462 <VarListEntry>
2463 <Term><Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
2464 <ListItem>
2465 <Para>
2466 <IndexTerm><Primary>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
2467 For version <Emphasis>n</Emphasis> of the GHC system, this will be <Literal>&num;define</Literal>d to
2468 <Emphasis>100n</Emphasis>.  So, for version 4.00, it is 400.
2469 </Para>
2470
2471 <Para>
2472 With any luck, <Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant> will be undefined in all other
2473 implementations that support C-style pre-processing.
2474 </Para>
2475
2476 <Para>
2477 (For reference: the comparable symbols for other systems are:
2478 <Constant>&lowbar;&lowbar;HUGS&lowbar;&lowbar;</Constant> for Hugs and <Constant>&lowbar;&lowbar;HBC&lowbar;&lowbar;</Constant> for Chalmers.)
2479 </Para>
2480
2481 <Para>
2482 NB. This macro is set when pre-processing both Haskell source and C
2483 source, including the C source generated from a Haskell module
2484 (i.e. <Filename>.hs</Filename>, <Filename>.lhs</Filename>, <Filename>.c</Filename> and <Filename>.hc</Filename> files).
2485 </Para>
2486 </ListItem>
2487 </VarListEntry>
2488 <VarListEntry>
2489 <Term><Constant>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
2490 <ListItem>
2491 <Para>
2492 <IndexTerm><Primary>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
2493 This symbol is defined when pre-processing Haskell (input) and
2494 pre-processing C (GHC output).  Since GHC from verion 4.00 now
2495 supports concurrent haskell by default, this symbol is always defined.
2496 </Para>
2497 </ListItem>
2498 </VarListEntry>
2499 <VarListEntry>
2500 <Term><Constant>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
2501 <ListItem>
2502 <Para>
2503 <IndexTerm><Primary>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
2504 Only defined when <Option>-parallel</Option> is in use!  This symbol is defined when
2505 pre-processing Haskell (input) and pre-processing C (GHC output).
2506 </Para>
2507 </ListItem>
2508 </VarListEntry>
2509 </VariableList>
2510 </Para>
2511
2512 <Para>
2513 Options other than the above can be forced through to the C
2514 pre-processor with the <Option>-opt</Option> flags (see
2515 <XRef LinkEnd="forcing-options-through">).
2516 </Para>
2517
2518 <Para>
2519 A small word of warning: <Option>-cpp</Option> is not friendly to &ldquo;string
2520 gaps&rdquo;.<IndexTerm><Primary>-cpp vs string gaps</Primary></IndexTerm><IndexTerm><Primary>string gaps vs
2521 -cpp</Primary></IndexTerm>.  In other words, strings such as the following:
2522 </Para>
2523
2524 <Para>
2525
2526 <ProgramListing>
2527 strmod = "\
2528 \ p \
2529 \ "
2530 </ProgramListing>
2531
2532 </Para>
2533
2534 <Para>
2535 don't work with <Option>-cpp</Option>; <Filename>/usr/bin/cpp</Filename> elides the
2536 backslash-newline pairs.
2537 </Para>
2538
2539 <Para>
2540 However, it appears that if you add a space at the end of the line,
2541 then <Command>cpp</Command> (at least GNU <Command>cpp</Command> and possibly other <Command>cpp</Command>s)
2542 leaves the backslash-space pairs alone and the string gap works as
2543 expected.
2544 </Para>
2545
2546 </Sect2>
2547
2548 <Sect2 id="options-C-compiler">
2549 <Title>Options affecting the C compiler (if applicable)
2550 </Title>
2551
2552 <Para>
2553 <IndexTerm><Primary>include-file options</Primary></IndexTerm>
2554 <IndexTerm><Primary>C compiler options</Primary></IndexTerm>
2555 <IndexTerm><Primary>GCC options</Primary></IndexTerm>
2556 </Para>
2557
2558 <Para>
2559 At the moment, quite a few common C-compiler options are passed on
2560 quietly to the C compilation of Haskell-compiler-generated C files.
2561 THIS MAY CHANGE.  Meanwhile, options so sent are:
2562 </Para>
2563
2564 <Para>
2565
2566 <InformalTable>
2567 <TGroup Cols="2">
2568 <ColSpec Align="Left" Colsep="0">
2569 <ColSpec Align="Left" Colsep="0">
2570 <TBody>
2571 <Row>
2572 <Entry><Option>-ansi</Option> </Entry>
2573 <Entry> do ANSI C (not K&amp;R) </Entry>
2574 </Row>
2575 <Row>
2576 <Entry>
2577 <Option>-pedantic</Option> </Entry>
2578 <Entry> be so</Entry>
2579 </Row>
2580 <Row>
2581 <Entry>
2582 <Option>-dgcc-lint</Option> </Entry>
2583 <Entry> (hack) short for &ldquo;make GCC very paranoid&rdquo;</Entry>
2584 </Row>
2585
2586 </TBody>
2587
2588 </TGroup>
2589 </InformalTable>
2590
2591 <IndexTerm><Primary>-ansi option (for GCC)</Primary></IndexTerm>
2592 <IndexTerm><Primary>-pedantic option (for GCC)</Primary></IndexTerm>
2593 <IndexTerm><Primary>-dgcc-lint option (GCC paranoia)</Primary></IndexTerm>
2594 </Para>
2595
2596 <Para>
2597 If you are compiling with lots of foreign calls, you may need to
2598 tell the C&nbsp;compiler about some <Literal>&num;include</Literal> files.  There is no real
2599 pretty way to do this, but you can use this hack from the
2600 command-line:
2601 </Para>
2602
2603 <Para>
2604
2605 <Screen>
2606 % ghc -c '-#include &#60;X/Xlib.h&#62;' Xstuff.lhs
2607 </Screen>
2608
2609 </Para>
2610
2611 </Sect2>
2612
2613 <Sect2 id="options-linker">
2614 <Title>Linking and consistency-checking
2615 </Title>
2616
2617 <Para>
2618 <IndexTerm><Primary>linker options</Primary></IndexTerm>
2619 <IndexTerm><Primary>ld options</Primary></IndexTerm>
2620 </Para>
2621
2622 <Para>
2623 GHC has to link your code with various libraries, possibly including:
2624 user-supplied, GHC-supplied, and system-supplied (<Option>-lm</Option> math
2625 library, for example).
2626 </Para>
2627
2628 <Para>
2629 <VariableList>
2630
2631 <VarListEntry>
2632 <Term><Option>-l&lt;FOO&gt;</Option>:</Term>
2633 <ListItem>
2634 <Para>
2635 <IndexTerm><Primary>-l&lt;lib&gt; option</Primary></IndexTerm>
2636 Link in a library named <Filename>lib&lt;FOO&gt;.a</Filename> which resides somewhere on the
2637 library directories path.
2638 </Para>
2639
2640 <Para>
2641 Because of the sad state of most UNIX linkers, the order of such
2642 options does matter.  Thus: <Command>ghc -lbar *.o</Command> is almost certainly
2643 wrong, because it will search <Filename>libbar.a</Filename> <Emphasis>before</Emphasis> it has
2644 collected unresolved symbols from the <Filename>*.o</Filename> files.
2645 <Command>ghc *.o -lbar</Command> is probably better.
2646 </Para>
2647
2648 <Para>
2649 The linker will of course be informed about some GHC-supplied
2650 libraries automatically; these are:
2651 </Para>
2652
2653 <Para>
2654
2655 <InformalTable>
2656 <TGroup Cols="2">
2657 <ColSpec Align="Left" Colsep="0">
2658 <ColSpec Align="Left" Colsep="0">
2659 <TBody>
2660 <Row>
2661 <Entry><Emphasis>-l equivalent</Emphasis> </Entry>
2662 <Entry> <Emphasis>description</Emphasis> </Entry>
2663 </Row>
2664
2665 <Row>
2666 <Entry>
2667 <Option>-lHSrts,-lHSclib</Option> </Entry>
2668 <Entry> basic runtime libraries </Entry>
2669 </Row>
2670 <Row>
2671 <Entry>
2672 <Option>-lHS</Option> </Entry>
2673 <Entry> standard Prelude library </Entry>
2674 </Row>
2675 <Row>
2676 <Entry>
2677 <Option>-lHS&lowbar;cbits</Option> </Entry>
2678 <Entry> C support code for standard Prelude library </Entry>
2679 </Row>
2680 <Row>
2681 <Entry>
2682 <Option>-lgmp</Option> </Entry>
2683 <Entry> GNU multi-precision library (for Integers)</Entry>
2684 </Row>
2685
2686 </TBody>
2687
2688 </TGroup>
2689 </InformalTable>
2690
2691 </Para>
2692
2693 <Para>
2694 <IndexTerm><Primary>-lHS library</Primary></IndexTerm>
2695 <IndexTerm><Primary>-lHS&lowbar;cbits library</Primary></IndexTerm>
2696 <IndexTerm><Primary>-lHSrts library</Primary></IndexTerm>
2697 <IndexTerm><Primary>-lgmp library</Primary></IndexTerm>
2698 </Para>
2699 </ListItem>
2700 </VarListEntry>
2701 <VarListEntry>
2702 <Term><Option>-package &lt;name&gt;</Option>:</Term>
2703 <ListItem>
2704 <Para>
2705 <IndexTerm><Primary>-package &lt;name&gt; option</Primary></IndexTerm>
2706 </Para>
2707
2708 <Para>
2709 If you are using a Haskell &ldquo;package&rdquo; (e.g., the POSIX
2710 library), just use the <Option>-package posix</Option> option, and the
2711 correct code should be linked in.  See <xref linkend="packages"> for
2712 more details.
2713 </Para>
2714 </ListItem>
2715 </VarListEntry>
2716 <VarListEntry>
2717 <Term><Option>-L&lt;dir&gt;</Option>:</Term>
2718 <ListItem>
2719 <Para>
2720 <IndexTerm><Primary>-L&lt;dir&gt; option</Primary></IndexTerm>
2721 Where to find user-supplied libraries&hellip;  Prepend the directory
2722 <Filename>&lt;dir&gt;</Filename> to the library directories path.
2723 </Para>
2724 </ListItem>
2725 </VarListEntry>
2726 <VarListEntry>
2727 <Term><Option>-static</Option>:</Term>
2728 <ListItem>
2729 <Para>
2730 <IndexTerm><Primary>-static option</Primary></IndexTerm>
2731 Tell the linker to avoid shared libraries.
2732 </Para>
2733 </ListItem>
2734 </VarListEntry>
2735 <VarListEntry>
2736 <Term><Option>-no-link-chk</Option> and <Option>-link-chk</Option>:</Term>
2737 <ListItem>
2738 <Para>
2739 <IndexTerm><Primary>-no-link-chk option</Primary></IndexTerm>
2740 <IndexTerm><Primary>-link-chk option</Primary></IndexTerm>
2741 <IndexTerm><Primary>consistency checking of executables</Primary></IndexTerm>
2742 By default, immediately after linking an executable, GHC verifies that
2743 the pieces that went into it were compiled with compatible flags; a
2744 &ldquo;consistency check&rdquo;.
2745 (This is to avoid mysterious failures caused by non-meshing of
2746 incompatibly-compiled programs; e.g., if one <Filename>.o</Filename> file was compiled
2747 for a parallel machine and the others weren't.)  You may turn off this
2748 check with <Option>-no-link-chk</Option>.  You can turn it (back) on with
2749 <Option>-link-chk</Option> (the default).
2750 </Para>
2751 </ListItem>
2752 </VarListEntry>
2753 <VarListEntry>
2754 <Term><Option>-no-hs-main</Option>:</Term>
2755 <ListItem>
2756 <Para>
2757 <IndexTerm><Primary>-no-hs-main option</Primary></IndexTerm>
2758 <IndexTerm><Primary>linking Haskell libraries with foreign code</Primary></IndexTerm>
2759 </Para>
2760
2761 <Para>
2762 In the event you want to include ghc-compiled code as part of another
2763 (non-Haskell) program, the RTS will not be supplying its definition of
2764 <Function>main()</Function> at link-time, you will have to. To signal that to the
2765 driver script when linking, use <Option>-no-hs-main</Option>.
2766 </Para>
2767
2768 <Para>
2769 Notice that since the command-line passed to the linker is rather
2770 involved, you probably want to use the ghc driver script to do the
2771 final link of your `mixed-language' application. This is not a
2772 requirement though, just try linking once with <Option>-v</Option> on to see what
2773 options the driver passes through to the linker.
2774 </Para>
2775 </ListItem>
2776 </VarListEntry>
2777 </VariableList>
2778 </Para>
2779
2780 </Sect2>
2781
2782 </Sect1>
2783
2784 <Sect1 id="sec-using-concurrent">
2785 <Title>Using Concurrent Haskell</Title>
2786
2787 <Para>
2788 <IndexTerm><Primary>Concurrent Haskell&mdash;use</Primary></IndexTerm>
2789 </Para>
2790
2791 <Para>
2792 GHC (as of version 4.00) supports Concurrent Haskell by default,
2793 without requiring a special option or libraries compiled in a certain
2794 way.  To get access to the support libraries for Concurrent Haskell
2795 (i.e. <Literal>Concurrent</Literal> and friends), use the
2796 <Option>-package concurrent</Option> option.
2797 </Para>
2798
2799 <Para>
2800 Three RTS options are provided for modifying the behaviour of the
2801 threaded runtime system.  See the descriptions of
2802 <Option>-C[&lt;us&gt;]</Option>, <Option>-q</Option>, and
2803 <Option>-t&lt;num&gt;</Option> in <XRef LinkEnd="parallel-rts-opts">.
2804 </Para>
2805
2806 <Para>
2807 Concurrent Haskell is described in more detail in <XRef
2808 LinkEnd="sec-Concurrent">.
2809 </Para>
2810
2811 </Sect1>
2812
2813 <Sect1 id="sec-using-parallel">
2814 <Title>Using Parallel Haskell</Title>
2815
2816 <Para>
2817 <IndexTerm><Primary>Parallel Haskell&mdash;use</Primary></IndexTerm>
2818 </Para>
2819
2820 <Para>
2821 &lsqb;You won't be able to execute parallel Haskell programs unless PVM3
2822 (Parallel Virtual Machine, version 3) is installed at your site.]
2823 </Para>
2824
2825 <Para>
2826 To compile a Haskell program for parallel execution under PVM, use the
2827 <Option>-parallel</Option> option,<IndexTerm><Primary>-parallel
2828 option</Primary></IndexTerm> both when compiling <Emphasis>and
2829 linking</Emphasis>.  You will probably want to <Literal>import
2830 Parallel</Literal> into your Haskell modules.
2831 </Para>
2832
2833 <Para>
2834 To run your parallel program, once PVM is going, just invoke it
2835 &ldquo;as normal&rdquo;.  The main extra RTS option is
2836 <Option>-N&lt;n&gt;</Option>, to say how many PVM
2837 &ldquo;processors&rdquo; your program to run on.  (For more details of
2838 all relevant RTS options, please see <XRef
2839 LinkEnd="parallel-rts-opts">.)
2840 </Para>
2841
2842 <Para>
2843 In truth, running Parallel Haskell programs and getting information
2844 out of them (e.g., parallelism profiles) is a battle with the vagaries of
2845 PVM, detailed in the following sections.
2846 </Para>
2847
2848 <Sect2>
2849 <Title>Dummy's guide to using PVM</Title>
2850
2851 <Para>
2852 <IndexTerm><Primary>PVM, how to use</Primary></IndexTerm>
2853 <IndexTerm><Primary>Parallel Haskell&mdash;PVM use</Primary></IndexTerm>
2854 Before you can run a parallel program under PVM, you must set the
2855 required environment variables (PVM's idea, not ours); something like,
2856 probably in your <Filename>.cshrc</Filename> or equivalent:
2857
2858 <ProgramListing>
2859 setenv PVM_ROOT /wherever/you/put/it
2860 setenv PVM_ARCH `$PVM_ROOT/lib/pvmgetarch`
2861 setenv PVM_DPATH $PVM_ROOT/lib/pvmd
2862 </ProgramListing>
2863
2864 </Para>
2865
2866 <Para>
2867 Creating and/or controlling your &ldquo;parallel machine&rdquo; is a purely-PVM
2868 business; nothing specific to Parallel Haskell.
2869 </Para>
2870
2871 <Para>
2872 You use the <Command>pvm</Command><IndexTerm><Primary>pvm command</Primary></IndexTerm> command to start PVM on your
2873 machine.  You can then do various things to control/monitor your
2874 &ldquo;parallel machine;&rdquo; the most useful being:
2875 </Para>
2876
2877 <Para>
2878 <InformalTable>
2879 <TGroup Cols=2>
2880 <ColSpec Align="Left">
2881 <TBody>
2882
2883 <Row>
2884 <Entry><KeyCombo><KeyCap>Control</KeyCap><KeyCap>D</KeyCap></KeyCombo></Entry>
2885 <Entry>exit <Command>pvm</Command>, leaving it running</Entry>
2886 </Row>
2887
2888 <Row>
2889 <Entry><Command>halt</Command></Entry>
2890 <Entry>kill off this &ldquo;parallel machine&rdquo; &amp; exit</Entry>
2891 </Row>
2892
2893 <Row>
2894 <Entry><Command>add &lt;host&gt;</Command></Entry>
2895 <Entry>add <Command>&lt;host&gt;</Command> as a processor</Entry>
2896 </Row>
2897
2898 <Row>
2899 <Entry><Command>delete &lt;host&gt;</Command></Entry>
2900 <Entry>delete <Command>&lt;host&gt;</Command></Entry>
2901 </Row>
2902
2903 <Row>
2904 <Entry><Command>reset</Command></Entry>
2905 <Entry>kill what's going, but leave PVM up</Entry>
2906 </Row>
2907
2908 <Row>
2909 <Entry><Command>conf</Command></Entry>
2910 <Entry>list the current configuration</Entry>
2911 </Row>
2912
2913 <Row>
2914 <Entry><Command>ps</Command></Entry>
2915 <Entry>report processes' status</Entry>
2916 </Row>
2917
2918 <Row>
2919 <Entry><Command>pstat &lt;pid&gt;</Command></Entry>
2920 <Entry>status of a particular process</Entry>
2921 </Row>
2922
2923 </TBody>
2924 </TGroup>
2925 </InformalTable>
2926 </Para>
2927
2928 <Para>
2929 The PVM documentation can tell you much, much more about <Command>pvm</Command>!
2930 </Para>
2931
2932 </Sect2>
2933
2934 <Sect2>
2935 <Title>Parallelism profiles</Title>
2936
2937 <Para>
2938 <IndexTerm><Primary>parallelism profiles</Primary></IndexTerm>
2939 <IndexTerm><Primary>profiles, parallelism</Primary></IndexTerm>
2940 <IndexTerm><Primary>visualisation tools</Primary></IndexTerm>
2941 </Para>
2942
2943 <Para>
2944 With Parallel Haskell programs, we usually don't care about the
2945 results&mdash;only with &ldquo;how parallel&rdquo; it was!  We want pretty pictures.
2946 </Para>
2947
2948 <Para>
2949 Parallelism profiles (&agrave; la <Command>hbcpp</Command>) can be generated with the
2950 <Option>-q</Option><IndexTerm><Primary>-q RTS option (concurrent, parallel)</Primary></IndexTerm> RTS option.  The
2951 per-processor profiling info is dumped into files named
2952 <Filename>&lt;full-path&gt;&lt;program&gt;.gr</Filename>.  These are then munged into a PostScript picture,
2953 which you can then display.  For example, to run your program
2954 <Filename>a.out</Filename> on 8 processors, then view the parallelism profile, do:
2955 </Para>
2956
2957 <Para>
2958
2959 <Screen>
2960 % ./a.out +RTS -N8 -q
2961 % grs2gr *.???.gr &#62; temp.gr     # combine the 8 .gr files into one
2962 % gr2ps -O temp.gr              # cvt to .ps; output in temp.ps
2963 % ghostview -seascape temp.ps   # look at it!
2964 </Screen>
2965
2966 </Para>
2967
2968 <Para>
2969 The scripts for processing the parallelism profiles are distributed
2970 in <Filename>ghc/utils/parallel/</Filename>.
2971 </Para>
2972
2973 </Sect2>
2974
2975 <Sect2>
2976 <Title>Other useful info about running parallel programs</Title>
2977
2978 <Para>
2979 The &ldquo;garbage-collection statistics&rdquo; RTS options can be useful for
2980 seeing what parallel programs are doing.  If you do either
2981 <Option>+RTS -Sstderr</Option><IndexTerm><Primary>-Sstderr RTS option</Primary></IndexTerm> or <Option>+RTS -sstderr</Option>, then
2982 you'll get mutator, garbage-collection, etc., times on standard
2983 error. The standard error of all PE's other than the `main thread'
2984 appears in <Filename>/tmp/pvml.nnn</Filename>, courtesy of PVM.
2985 </Para>
2986
2987 <Para>
2988 Whether doing <Option>+RTS -Sstderr</Option> or not, a handy way to watch
2989 what's happening overall is: <Command>tail -f /tmp/pvml.nnn</Command>.
2990 </Para>
2991
2992 </Sect2>
2993
2994 <Sect2 id="parallel-rts-opts">
2995 <Title>RTS options for Concurrent/Parallel Haskell
2996 </Title>
2997
2998 <Para>
2999 <IndexTerm><Primary>RTS options, concurrent</Primary></IndexTerm>
3000 <IndexTerm><Primary>RTS options, parallel</Primary></IndexTerm>
3001 <IndexTerm><Primary>Concurrent Haskell&mdash;RTS options</Primary></IndexTerm>
3002 <IndexTerm><Primary>Parallel Haskell&mdash;RTS options</Primary></IndexTerm>
3003 </Para>
3004
3005 <Para>
3006 Besides the usual runtime system (RTS) options
3007 (<XRef LinkEnd="runtime-control">), there are a few options particularly
3008 for concurrent/parallel execution.
3009 </Para>
3010
3011 <Para>
3012 <VariableList>
3013
3014 <VarListEntry>
3015 <Term><Option>-N&lt;N&gt;</Option>:</Term>
3016 <ListItem>
3017 <Para>
3018 <IndexTerm><Primary>-N&lt;N&gt; RTS option (parallel)</Primary></IndexTerm>
3019 (PARALLEL ONLY) Use <Literal>&lt;N&gt;</Literal> PVM processors to run this program;
3020 the default is 2.
3021 </Para>
3022 </ListItem>
3023 </VarListEntry>
3024 <VarListEntry>
3025 <Term><Option>-C[&lt;us&gt;]</Option>:</Term>
3026 <ListItem>
3027 <Para>
3028 <IndexTerm><Primary>-C&lt;us&gt; RTS option</Primary></IndexTerm> Sets
3029 the context switch interval to <Literal>&lt;s&gt;</Literal> seconds.
3030 A context switch will occur at the next heap block allocation after
3031 the timer expires (a heap block allocation occurs every 4k of
3032 allocation).  With <Option>-C0</Option> or <Option>-C</Option>,
3033 context switches will occur as often as possible (at every heap block
3034 allocation).  By default, context switches occur every 20ms
3035 milliseconds.  Note that GHC's internal timer ticks every 20ms, and
3036 the context switch timer is always a multiple of this timer, so 20ms
3037 is the maximum granularity available for timed context switches.
3038 </Para>
3039 </ListItem>
3040 </VarListEntry>
3041 <VarListEntry>
3042 <Term><Option>-q[v]</Option>:</Term>
3043 <ListItem>
3044 <Para>
3045 <IndexTerm><Primary>-q RTS option</Primary></IndexTerm>
3046 (PARALLEL ONLY) Produce a quasi-parallel profile of thread activity,
3047 in the file <FIlename>&lt;program&gt;.qp</FIlename>.  In the style of <Command>hbcpp</Command>, this profile
3048 records the movement of threads between the green (runnable) and red
3049 (blocked) queues.  If you specify the verbose suboption (<Option>-qv</Option>), the
3050 green queue is split into green (for the currently running thread
3051 only) and amber (for other runnable threads).  We do not recommend
3052 that you use the verbose suboption if you are planning to use the
3053 <Command>hbcpp</Command> profiling tools or if you are context switching at every heap
3054 check (with <Option>-C</Option>).
3055 </Para>
3056 </ListItem>
3057 </VarListEntry>
3058 <VarListEntry>
3059 <Term><Option>-t&lt;num&gt;</Option>:</Term>
3060 <ListItem>
3061 <Para>
3062 <IndexTerm><Primary>-t&lt;num&gt; RTS option</Primary></IndexTerm>
3063 (PARALLEL ONLY) Limit the number of concurrent threads per processor
3064 to <Literal>&lt;num&gt;</Literal>.  The default is 32.  Each thread requires slightly over 1K
3065 <Emphasis>words</Emphasis> in the heap for thread state and stack objects.  (For
3066 32-bit machines, this translates to 4K bytes, and for 64-bit machines,
3067 8K bytes.)
3068 </Para>
3069 </ListItem>
3070 </VarListEntry>
3071 <VarListEntry>
3072 <Term><Option>-d</Option>:</Term>
3073 <ListItem>
3074 <Para>
3075 <IndexTerm><Primary>-d RTS option (parallel)</Primary></IndexTerm>
3076 (PARALLEL ONLY) Turn on debugging.  It pops up one xterm (or GDB, or
3077 something&hellip;) per PVM processor.  We use the standard <Command>debugger</Command>
3078 script that comes with PVM3, but we sometimes meddle with the
3079 <Command>debugger2</Command> script.  We include ours in the GHC distribution,
3080 in <Filename>ghc/utils/pvm/</Filename>.
3081 </Para>
3082 </ListItem>
3083 </VarListEntry>
3084 <VarListEntry>
3085 <Term><Option>-e&lt;num&gt;</Option>:</Term>
3086 <ListItem>
3087 <Para>
3088 <IndexTerm><Primary>-e&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
3089 (PARALLEL ONLY) Limit the number of pending sparks per processor to
3090 <Literal>&lt;num&gt;</Literal>. The default is 100. A larger number may be appropriate if
3091 your program generates large amounts of parallelism initially.
3092 </Para>
3093 </ListItem>
3094 </VarListEntry>
3095 <VarListEntry>
3096 <Term><Option>-Q&lt;num&gt;</Option>:</Term>
3097 <ListItem>
3098 <Para>
3099 <IndexTerm><Primary>-Q&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
3100 (PARALLEL ONLY) Set the size of packets transmitted between processors
3101 to <Literal>&lt;num&gt;</Literal>. The default is 1024 words. A larger number may be
3102 appropriate if your machine has a high communication cost relative to
3103 computation speed.
3104 </Para>
3105 </ListItem>
3106 </VarListEntry>
3107 </VariableList>
3108 </Para>
3109
3110 </Sect2>
3111
3112 </Sect1>
3113
3114 &runtime
3115 &debug
3116
3117 </Chapter>
3118
3119 <!-- Emacs stuff:
3120      ;;; Local Variables: ***
3121      ;;; mode: sgml ***
3122      ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***
3123      ;;; End: ***
3124  -->