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