[project @ 2000-07-31 10:06:30 by simonmar]
[ghc-hetmet.git] / ghc / docs / users_guide / intro.sgml
1 <Chapter id="introduction-GHC">
2 <Title>Introduction to GHC
3 </Title>
4
5 <Para>
6 This is a guide to using the Glasgow Haskell compilation (GHC) system. It is
7 a batch compiler for the Haskell&nbsp;98 language, with support for various
8 Glasgow-only extensions. In this document, we assume that GHC has been
9 installed at your site as <Literal>ghc</Literal>.  A separate document,
10 &ldquo;Building and Installing the Glasgow Functional Programming Tools Suite&rdquo;,
11 describes how to install <Literal>ghc</Literal>.
12 </Para>
13
14 <Para>
15 Many people will use GHC very simply: compile some
16 modules&mdash;<Literal>ghc -c -O Foo.hs Bar.hs</Literal>; and link them&mdash;
17 <Literal>ghc -o wiggle -O Foo.o Bar.o</Literal>.
18 </Para>
19
20 <Para>
21 But if you need to do something more complicated, GHC can do that,
22 too:
23
24 <Screen>
25 ghc -c -O -fno-foldr-build -dcore-lint -fvia-C -ddump-simpl Foo.lhs
26 </Screen>
27
28 Stay tuned&mdash;all will be revealed!
29 </Para>
30
31 <Para>
32 The rest of this section provide some tutorial information
33 on batch-style compilation; if you're familiar with these concepts
34 already, then feel free to skip to the next section.
35 </Para>
36
37 <Sect1 id="batch-system-parts">
38 <Title>The (batch) compilation system components</Title>
39
40 <Para>
41 The Glorious Haskell Compilation System, as with most UNIX (batch)
42 compilation systems, has several interacting parts:
43
44 <OrderedList>
45 <ListItem>
46 <Para>
47 A <Emphasis>driver</Emphasis><IndexTerm><Primary>driver
48 program</Primary></IndexTerm>
49 <Literal>ghc</Literal><IndexTerm><Primary>ghc</Primary></IndexTerm>&mdash;which
50 you usually think of as &ldquo;the compiler&rdquo;&mdash;is a program
51 that merely invokes/glues-together the other pieces of the system
52 (listed below), passing the right options to each, slurping in the
53 right libraries, etc.
54 </Para>
55 </ListItem>
56
57 <ListItem>
58 <Para>
59 A <Emphasis>literate pre-processor</Emphasis>
60 <IndexTerm><Primary>literate pre-processor</Primary></IndexTerm>
61 <IndexTerm><Primary>pre-processor, literate</Primary></IndexTerm>
62 <Literal>unlit</Literal><IndexTerm><Primary>unlit</Primary></IndexTerm> that extracts Haskell
63 code from a literate script; used if you believe in that sort of
64 thing.
65 </Para>
66 </ListItem>
67
68 <ListItem>
69 <Para>
70 The <Emphasis>Haskellised C pre-processor</Emphasis>
71 <IndexTerm><Primary>Haskellised C pre-processor</Primary></IndexTerm>
72 <IndexTerm><Primary>C pre-processor, Haskellised</Primary></IndexTerm>
73 <IndexTerm><Primary>pre-processor, Haskellised C</Primary></IndexTerm>
74 <Literal>hscpp</Literal>,<IndexTerm><Primary>hscpp</Primary></IndexTerm> only needed by people requiring conditional
75 compilation, probably for large systems.  The &ldquo;Haskellised&rdquo; part
76 just means that <Literal>&num;line</Literal> directives in the output have been
77 converted into proper Haskell <Literal>&lcub;-&num; LINE ... -&rcub;</Literal> pragmas. You must give an explicit <Literal>-cpp</Literal> option 
78 <IndexTerm><Primary>-cpp option</Primary></IndexTerm> for the C pre-processor to be invoked.
79 </Para>
80 </ListItem>
81
82 <ListItem>
83 <Para>
84 The <Emphasis>Haskell compiler</Emphasis>
85 <IndexTerm><Primary>Haskell compiler</Primary></IndexTerm>
86 <IndexTerm><Primary>compiler, Haskell</Primary></IndexTerm>
87 <Literal>hsc</Literal>,<IndexTerm><Primary>hsc</Primary></IndexTerm>
88 which&mdash;in normal use&mdash;takes its input from the C pre-processor
89 and produces assembly-language output (sometimes: ANSI C output).
90 </Para>
91 </ListItem>
92
93 <ListItem>
94 <Para>
95 The <Emphasis>ANSI&nbsp;C Haskell high-level assembler :-)</Emphasis>
96 <IndexTerm><Primary>ANSI C compiler</Primary></IndexTerm>
97 <IndexTerm><Primary>high-level assembler</Primary></IndexTerm>
98 <IndexTerm><Primary>assembler, high-level</Primary></IndexTerm>
99 compiles <Literal>hsc</Literal>'s C output into assembly language for a particular
100 target architecture.  In fact, the only C compiler we currently
101 support is <Literal>gcc</Literal>, because we make use of certain extensions to the
102 C language only supported by gcc.  Version 2.x is a must; we recommend
103 version 2.7.2.1 for stability (we've heard both good and bad reports
104 of later versions).
105 </Para>
106 </ListItem>
107
108 <ListItem>
109 <Para>
110 The <Emphasis>assembler</Emphasis><IndexTerm><Primary>assembler</Primary></IndexTerm>&mdash;a standard UNIX one, probably
111 <Literal>as</Literal><IndexTerm><Primary>as</Primary></IndexTerm>.
112 </Para>
113 </ListItem>
114
115 <ListItem>
116 <Para>
117 The <Emphasis>linker</Emphasis><IndexTerm><Primary>linker</Primary></IndexTerm>&mdash;a standard UNIX one, probably
118 <Literal>ld</Literal>.<IndexTerm><Primary>ld</Primary></IndexTerm>
119 </Para>
120 </ListItem>
121
122 <ListItem>
123 <Para>
124 A <Emphasis>runtime system</Emphasis>,<IndexTerm><Primary>runtime system</Primary></IndexTerm> including (most notably)
125 a storage manager; the linker links in the code for this.
126 </Para>
127 </ListItem>
128
129 <ListItem>
130 <Para>
131 The <Emphasis>Haskell standard prelude</Emphasis><IndexTerm><Primary>standard prelude</Primary></IndexTerm>, a
132 large library of standard functions, is linked in as well.
133 </Para>
134 </ListItem>
135
136 <ListItem>
137 <Para>
138 Parts of other <Emphasis>installed libraries</Emphasis> that you have at your site may be linked in also.
139 </Para>
140 </ListItem>
141
142 </OrderedList>
143 </Para>
144
145 </Sect1>
146
147 <Sect1 id="compile-what-really-happens">
148 <Title>What really happens when I &ldquo;compile&rdquo; a Haskell program?
149 </Title>
150
151 <Para>
152 You invoke the Glasgow Haskell compilation system through the
153 driver program <Literal>ghc</Literal>.<IndexTerm><Primary>ghc</Primary></IndexTerm> For example, if you had typed a
154 literate &ldquo;Hello, world!&rdquo; program into <Literal>hello.lhs</Literal>, and you then
155 invoked:
156
157 <Screen>
158 ghc hello.lhs
159 </Screen>
160
161 </Para>
162
163 <Para>
164 the following would happen:
165
166 <OrderedList>
167 <ListItem>
168
169 <Para>
170 The file <Literal>hello.lhs</Literal> is run through the literate-program
171 code extractor <Literal>unlit</Literal><IndexTerm><Primary>unlit</Primary></IndexTerm>, feeding its output to
172
173 </Para>
174 </ListItem>
175 <ListItem>
176
177 <Para>
178 The Haskell compiler proper <Literal>hsc</Literal><IndexTerm><Primary>hsc</Primary></IndexTerm>, which produces
179 input for
180
181 </Para>
182 </ListItem>
183 <ListItem>
184
185 <Para>
186 The assembler (or that ubiquitous &ldquo;high-level assembler,&rdquo; a C
187 compiler), which produces an object file and passes it to
188
189 </Para>
190 </ListItem>
191 <ListItem>
192
193 <Para>
194 The linker, which links your code with the appropriate libraries
195 (including the standard prelude), producing an executable program in
196 the default output file named <Literal>a.out</Literal>.
197 </Para>
198 </ListItem>
199
200 </OrderedList>
201
202 </Para>
203
204 <Para>
205 You have considerable control over the compilation process.  You feed
206 command-line arguments (call them &ldquo;options,&rdquo; for short) to the
207 driver, <Literal>ghc</Literal>; the &ldquo;types&rdquo; of the input files (as encoded in
208 their names' suffixes) also matter.
209 </Para>
210
211 <Para>
212 Here's hoping this is enough background so that you can read the rest
213 of this guide!
214 </Para>
215
216 </Sect1>
217
218   <Sect1 id="mailing-lists-GHC">
219     <Title>Meta-information: Web sites, mailing lists, etc.</Title>
220
221     <IndexTerm><Primary>mailing lists, Glasgow Haskell</Primary></IndexTerm>
222     <IndexTerm><Primary>Glasgow Haskell mailing lists</Primary></IndexTerm>
223
224 <Para>On the World-Wide Web, there are several URLs of likely
225 interest:</Para>
226
227 <Para>
228
229 <ItemizedList>
230 <ListItem>
231
232 <Para>
233   <ULink
234 URL="http://www.haskell.org/"
235 >Haskell home page</ULink
236 >
237 </Para>
238 </ListItem>
239 <ListItem>
240
241 <Para>
242   <ULink
243 URL="http://www.haskell.org/ghc/"
244 >GHC home page</ULink
245 >
246 </Para>
247 </ListItem>
248 <ListItem>
249
250 <Para>
251   <ULink
252 URL="http://www.cs.nott.ac.uk/Department/Staff/mpj/faq.html"
253 >comp.lang.functional FAQ</ULink
254 >
255 </Para>
256 </ListItem>
257
258 </ItemizedList>
259
260 </Para>
261
262 <Para>
263 We run two mailing lists about Glasgow Haskell.  We encourage you to
264 join, as you feel is appropriate.
265 </Para>
266
267 <Para>
268 <VariableList>
269
270 <VarListEntry>
271 <Term>glasgow-haskell-users:</Term>
272 <ListItem>
273 <Para>
274 This list is for GHC users to chat among themselves.  Subscribe by
275 sending mail to <email>majordomo@haskell.org</email>, with a message
276 body (not header) like this:
277 </Para>
278
279 <Para>
280
281 <Screen> 
282 subscribe glasgow-haskell-users MyName &#60;m.y.self@bigbucks.com&#62; 
283 </Screen>
284  
285 </Para>
286
287 <Para>
288 (The last bit is your all-important e-mail address, of course.)
289 </Para>
290
291 <Para>
292 To communicate with your fellow users, send mail to <email>glasgow-haskell-users@haskell.org</email>.
293 </Para>
294
295 <Para>
296 To contact the list administrator, send mail to
297 <email>owner-glasgow-haskell-users@haskell.org</email>.  An archive
298 of the list is available on the Web at the <ULink
299 URL="http://www.mail-archive.com/glasgow-haskell-users@haskell.org">glasgow-haskell-users
300 mailing list archive</ULink>.
301 </Para>
302 </ListItem>
303 </VarListEntry>
304 <VarListEntry>
305 <Term>glasgow-haskell-bugs:</Term>
306 <ListItem>
307 <Para>
308 Send bug reports for GHC to this address!  The sad and lonely people
309 who subscribe to this list will muse upon what's wrong and what you
310 might do about it.
311 </Para>
312
313 <Para>
314 Subscribe via <email>majordomo@haskell.org</email> with:
315 </Para>
316
317 <Para>
318
319 <Screen>
320 subscribe glasgow-haskell-bugs My Name &#60;m.y.self@hackers.r.us&#62;
321 </Screen>
322
323 </Para>
324
325 <Para>
326 Again, you may contact the list administrator at <email>owner-glasgow-haskell-bugs@haskell.org</email>.
327 And, yes, an archive of the list is available on the Web at the <ULink
328 URL="http://www.mail-archive.com/glasgow-haskell-bugs@haskell.org">
329 glasgow-haskell-bugs mailing list archive</ULink
330 >
331 </Para>
332 </ListItem>
333 </VarListEntry>
334 </VariableList>
335 </Para>
336
337 <Para>
338 There is also the general Haskell mailing list.  Subscribe by sending
339 email to <email>majordomo@haskell.org</email>, with the usual message body:
340 </Para>
341
342 <Para>
343
344 <Screen>
345 subscribe haskell My Name &#60;m.y.self@fp.rules.ok.org&#62;
346 </Screen>
347
348 </Para>
349
350 <Para>
351 Some Haskell-related discussion takes place in the Usenet newsgroup
352 <Literal>comp.lang.functional</Literal>.
353 </Para>
354
355   </Sect1>
356
357   <sect1 id="version-numbering">
358     <title>GHC version numbering policy</title>
359     <indexterm><primary>version, of ghc</primary></indexterm>
360
361     <para>As of GHC version 4.08, we have adopted the following
362     policy for numbering GHC versions:</para>
363
364     <variablelist>
365       <varlistentry>
366         <term>Stable Releases</term>
367         <listitem>
368           <para>These are numbered <literal>x.yy.z</literal>, where
369           <literal>yy</literal> is <emphasis>even</emphasis>, and
370           <literal>z</literal> is the patchlevel number (the trailing
371           <literal>.z</literal> can be omitted if <literal>z</literal>
372           is zero).  Patchlevels are bug-fix releases only, and never
373           change the programmer interface to any system-supplied code.
374           However, if you install a new patchlevel over an old one you
375           may need to recompile any code that was compiled against the
376           old libraries.</para>
377
378           <para>The value of <literal>__GLASGOW_HASKELL__</literal>
379           (see <xref linkend="c-pre-processor">) for a major release
380           <literal>x.yy.z</literal> is the integer
381           <literal>xyy</literal>.</para>
382           <indexterm>
383             <primary><literal>__GLASGOW_HASKELL__</literal></primary>
384           </indexterm>
385         </listitem>
386       </varlistentry>
387       
388       <varlistentry>
389         <term>Snapshots/unstable releases</term>
390         <listitem>
391           <para>We may make snapshot releases of the current
392           development sources from time to time, and the current
393           sources are always available via the CVS repository (see the
394           GHC web site for details).</para>
395
396           <para>Snapshot releases are named
397           <literal>x.yy.YYYYMMDD</literal> where <literal>yy</literal>
398           is <emphasis>odd</emphasis>, and <literal>YYYYMMDD</literal>
399           is the date of the sources from which the snapshot was
400           built.  In theory, you can check out the exact same sources
401           from the CVS repository using this date.</para>
402
403           <para>The value of <literal>__GLASGOW_HASKELL__</literal>
404           for a snapshot release is the integer
405           <literal>xyy</literal>.  You should never write any
406           conditional code which tests for this value, however: since
407           interfaces change on a day-to-day basis, and we don't have
408           finer granularity in the values of
409           <literal>__GLASGOW_HASKELL__</literal>, you should only
410           conditionally compile using predicates which test whether
411           <literal>__GLASGOW_HASKELL__</literal> is equal to, later
412           than, or earlier than a given major release.</para>
413           <indexterm>
414             <primary><literal>__GLASGOW_HASKELL__</literal></primary>
415           </indexterm>
416         </listitem>
417       </varlistentry>
418     </variablelist>
419     
420     <para>The version number of your copy of GHC can be found by
421     invoking <literal>ghc</literal> with the
422     <literal>--version</literal> flag.</para>
423   </sect1>
424
425
426 &relnotes
427
428 </Chapter>
429
430 <!-- Emacs stuff:
431      ;;; Local Variables: ***
432      ;;; mode: sgml ***
433      ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***
434      ;;; End: ***
435  -->