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.
269 <Term>glasgow-haskell-users:</Term>
272 This list is for GHC users to chat among themselves. Subscription can
273 be done on-line at <ulink
274 url="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users"><literal>http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</literal></ulink>.</para>
277 To communicate with your fellow users, send mail to <email>glasgow-haskell-users@haskell.org</email>.
281 To contact the list administrator, send mail to
282 <email>glasgow-haskell-users-admin@haskell.org</email>. An archive
283 of the list is available at <ulink url="http://www.haskell.org/pipermail/glasgow-haskell-users/"><literal>http://www.haskell.org/pipermail/glasgow-haskell-users/</literal></ulink>.
289 <Term>glasgow-haskell-bugs:</Term>
292 Send bug reports for GHC to this address! The sad and lonely people
293 who subscribe to this list will muse upon what's wrong and what you
297 <para>Subscription can be done on-line at <ulink
298 url="http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs"><literal>http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs</literal></ulink>.</para>
301 Again, you may contact the list administrator at
302 <email>glasgow-haskell-bugs-admin@haskell.org</email>. And, yes, an
303 archive of the list is available on the Web at the <ulink url="http://www.haskell.org/pipermail/glasgow-haskell-bugs/"><literal>http://www.haskell.org/pipermail/glasgow-haskell-bugs/</literal></ulink>.</Para>
308 <term>cvs-ghc:</term>
310 <para>The hardcore GHC developers hang out here. This
311 list also gets commit message from the CVS repository.
312 There are several other similar lists for other parts
313 of the CVS repository
314 (eg. <literal>cvs-hslibs</literal>,
315 <literal>cvs-happy</literal>,
316 <literal>cvs-hdirect</literal> etc.)</para>
318 <para>To subscribe: <ulink
319 url="http://www.haskell.org/mailman/listinfo/cvs-ghc"><literal>http://www.haskell.org/mailman/listinfo/cvs-ghc</literal></ulink></para>
326 There are several other haskell and GHC-related mailing lists served
327 by <literal>www.haskell.org</literal>. Go to <ulink
328 url="http://www.haskell.org/mailman/listinfo/"><literal>http://www.haskell.org/mailman/listinfo/</literal></ulink>
329 for the full list.</Para>
332 Some Haskell-related discussion also takes place in the Usenet
333 newsgroup <Literal>comp.lang.functional</Literal>.
338 <sect1 id="version-numbering">
339 <title>GHC version numbering policy</title>
340 <indexterm><primary>version, of ghc</primary></indexterm>
342 <para>As of GHC version 4.08, we have adopted the following
343 policy for numbering GHC versions:</para>
347 <term>Stable Releases</term>
349 <para>These are numbered <literal>x.yy.z</literal>, where
350 <literal>yy</literal> is <emphasis>even</emphasis>, and
351 <literal>z</literal> is the patchlevel number (the trailing
352 <literal>.z</literal> can be omitted if <literal>z</literal>
353 is zero). Patchlevels are bug-fix releases only, and never
354 change the programmer interface to any system-supplied code.
355 However, if you install a new patchlevel over an old one you
356 may need to recompile any code that was compiled against the
357 old libraries.</para>
359 <para>The value of <literal>__GLASGOW_HASKELL__</literal>
360 (see <xref linkend="c-pre-processor">) for a major release
361 <literal>x.yy.z</literal> is the integer
362 <literal>xyy</literal>.</para>
364 <primary><literal>__GLASGOW_HASKELL__</literal></primary>
370 <term>Snapshots/unstable releases</term>
372 <para>We may make snapshot releases of the current
373 development sources from time to time, and the current
374 sources are always available via the CVS repository (see the
375 GHC web site for details).</para>
377 <para>Snapshot releases are named
378 <literal>x.yy.YYYYMMDD</literal> where <literal>yy</literal>
379 is <emphasis>odd</emphasis>, and <literal>YYYYMMDD</literal>
380 is the date of the sources from which the snapshot was
381 built. In theory, you can check out the exact same sources
382 from the CVS repository using this date.</para>
384 <para>The value of <literal>__GLASGOW_HASKELL__</literal>
385 for a snapshot release is the integer
386 <literal>xyy</literal>. You should never write any
387 conditional code which tests for this value, however: since
388 interfaces change on a day-to-day basis, and we don't have
389 finer granularity in the values of
390 <literal>__GLASGOW_HASKELL__</literal>, you should only
391 conditionally compile using predicates which test whether
392 <literal>__GLASGOW_HASKELL__</literal> is equal to, later
393 than, or earlier than a given major release.</para>
395 <primary><literal>__GLASGOW_HASKELL__</literal></primary>
401 <para>The version number of your copy of GHC can be found by
402 invoking <literal>ghc</literal> with the
403 <literal>--version</literal> flag.</para>
412 ;;; Local Variables: ***
414 ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***