1 <Chapter id="introduction-GHC">
2 <Title>Introduction to GHC
6 This is a guide to using the Glasgow Haskell compilation (GHC) system. It is
7 a batch compiler for the Haskell 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 “Building and Installing the Glasgow Functional Programming Tools Suite”,
11 describes how to install <Literal>ghc</Literal>.
15 Many people will use GHC very simply: compile some
16 modules—<Literal>ghc -c -O Foo.hs Bar.hs</Literal>; and link them—
17 <Literal>ghc -o wiggle -O Foo.o Bar.o</Literal>.
21 But if you need to do something more complicated, GHC can do that,
25 ghc -c -O -fno-foldr-build -dcore-lint -fvia-C -ddump-simpl Foo.lhs
28 Stay tuned—all will be revealed!
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.
37 <Sect1 id="batch-system-parts">
38 <Title>The (batch) compilation system components</Title>
41 The Glorious Haskell Compilation System, as with most UNIX (batch)
42 compilation systems, has several interacting parts:
47 A <Emphasis>driver</Emphasis><IndexTerm><Primary>driver
48 program</Primary></IndexTerm>
49 <Literal>ghc</Literal><IndexTerm><Primary>ghc</Primary></IndexTerm>—which
50 you usually think of as “the compiler”—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
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
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 “Haskellised” part
76 just means that <Literal>#line</Literal> directives in the output have been
77 converted into proper Haskell <Literal>{-# LINE ... -}</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.
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—in normal use—takes its input from the C pre-processor
89 and produces assembly-language output (sometimes: ANSI C output).
95 The <Emphasis>ANSI 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
110 The <Emphasis>assembler</Emphasis><IndexTerm><Primary>assembler</Primary></IndexTerm>—a standard UNIX one, probably
111 <Literal>as</Literal><IndexTerm><Primary>as</Primary></IndexTerm>.
117 The <Emphasis>linker</Emphasis><IndexTerm><Primary>linker</Primary></IndexTerm>—a standard UNIX one, probably
118 <Literal>ld</Literal>.<IndexTerm><Primary>ld</Primary></IndexTerm>
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.
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.
138 Parts of other <Emphasis>installed libraries</Emphasis> that you have at your site may be linked in also.
147 <Sect1 id="compile-what-really-happens">
148 <Title>What really happens when I “compile” a Haskell program?
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 “Hello, world!” program into <Literal>hello.lhs</Literal>, and you then
164 the following would happen:
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
178 The Haskell compiler proper <Literal>hsc</Literal><IndexTerm><Primary>hsc</Primary></IndexTerm>, which produces
186 The assembler (or that ubiquitous “high-level assembler,” a C
187 compiler), which produces an object file and passes it to
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>.
205 You have considerable control over the compilation process. You feed
206 command-line arguments (call them “options,” for short) to the
207 driver, <Literal>ghc</Literal>; the “types” of the input files (as encoded in
208 their names' suffixes) also matter.
212 Here's hoping this is enough background so that you can read the rest
218 <Sect1 id="mailing-lists-GHC">
219 <Title>Meta-information: Web sites, mailing lists, etc.</Title>
221 <IndexTerm><Primary>mailing lists, Glasgow Haskell</Primary></IndexTerm>
222 <IndexTerm><Primary>Glasgow Haskell mailing lists</Primary></IndexTerm>
224 <Para>On the World-Wide Web, there are several URLs of likely
234 URL="http://www.haskell.org/"
235 >Haskell home page</ULink
243 URL="http://www.haskell.org/ghc/"
244 >GHC home page</ULink
252 URL="http://www.cs.nott.ac.uk/Department/Staff/mpj/faq.html"
253 >comp.lang.functional FAQ</ULink
263 We run two mailing lists about Glasgow Haskell. We encourage you to
264 join, as you feel is appropriate.
271 <Term>glasgow-haskell-users:</Term>
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:
282 subscribe glasgow-haskell-users MyName <m.y.self@bigbucks.com>
288 (The last bit is your all-important e-mail address, of course.)
292 To communicate with your fellow users, send mail to <email>glasgow-haskell-users@haskell.org</email>.
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>.
305 <Term>glasgow-haskell-bugs:</Term>
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
314 Subscribe via <email>majordomo@haskell.org</email> with:
320 subscribe glasgow-haskell-bugs My Name <m.y.self@hackers.r.us>
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
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:
345 subscribe haskell My Name <m.y.self@fp.rules.ok.org>
351 Some Haskell-related discussion takes place in the Usenet newsgroup
352 <Literal>comp.lang.functional</Literal>.
357 <sect1 id="version-numbering">
358 <title>GHC version numbering policy</title>
359 <indexterm><primary>version, of ghc</primary></indexterm>
361 <para>As of GHC version 4.08, we have adopted the following
362 policy for numbering GHC versions:</para>
366 <term>Stable Releases</term>
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>
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>
383 <primary><literal>__GLASGOW_HASKELL__</literal></primary>
389 <term>Snapshots/unstable releases</term>
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>
396 <para>Snapshot releases are named
397 <literal>x.yy.DDMMYYYY</literal> where <literal>yy</literal>
398 is <emphasis>odd</emphasis>, and <literal>DDMMYYYY</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>
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>
414 <primary><literal>__GLASGOW_HASKELL__</literal></primary>
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>
431 ;;; Local Variables: ***
433 ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***