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 program</Primary></IndexTerm>
48 <Literal>ghc</Literal><IndexTerm><Primary>ghc</Primary></IndexTerm>—which
49 you usually think of as “the compiler”—is a program that merely
50 invokes/glues-together the other pieces of the system (listed below),
51 passing the right options to each, slurping in the right libraries, etc.
57 A <Emphasis>literate pre-processor</Emphasis>
58 <IndexTerm><Primary>literate pre-processor</Primary></IndexTerm>
59 <IndexTerm><Primary>pre-processor, literate</Primary></IndexTerm>
60 <Literal>unlit</Literal><IndexTerm><Primary>unlit</Primary></IndexTerm> that extracts Haskell
61 code from a literate script; used if you believe in that sort of
68 The <Emphasis>Haskellised C pre-processor</Emphasis>
69 <IndexTerm><Primary>Haskellised C pre-processor</Primary></IndexTerm>
70 <IndexTerm><Primary>C pre-processor, Haskellised</Primary></IndexTerm>
71 <IndexTerm><Primary>pre-processor, Haskellised C</Primary></IndexTerm>
72 <Literal>hscpp</Literal>,<IndexTerm><Primary>hscpp</Primary></IndexTerm> only needed by people requiring conditional
73 compilation, probably for large systems. The “Haskellised” part
74 just means that <Literal>#line</Literal> directives in the output have been
75 converted into proper Haskell <Literal>{-# LINE ... -}</Literal> pragmas. You must give an explicit <Literal>-cpp</Literal> option
76 <IndexTerm><Primary>-cpp option</Primary></IndexTerm> for the C pre-processor to be invoked.
82 The <Emphasis>Haskell compiler</Emphasis>
83 <IndexTerm><Primary>Haskell compiler</Primary></IndexTerm>
84 <IndexTerm><Primary>compiler, Haskell</Primary></IndexTerm>
85 <Literal>hsc</Literal>,<IndexTerm><Primary>hsc</Primary></IndexTerm>
86 which—in normal use—takes its input from the C pre-processor
87 and produces assembly-language output (sometimes: ANSI C output).
93 The <Emphasis>ANSI C Haskell high-level assembler :-)</Emphasis>
94 <IndexTerm><Primary>ANSI C compiler</Primary></IndexTerm>
95 <IndexTerm><Primary>high-level assembler</Primary></IndexTerm>
96 <IndexTerm><Primary>assembler, high-level</Primary></IndexTerm>
97 compiles <Literal>hsc</Literal>'s C output into assembly language for a particular
98 target architecture. In fact, the only C compiler we currently
99 support is <Literal>gcc</Literal>, because we make use of certain extensions to the
100 C language only supported by gcc. Version 2.x is a must; we recommend
101 version 2.7.2.1 for stability (we've heard both good and bad reports
108 The <Emphasis>assembler</Emphasis><IndexTerm><Primary>assembler</Primary></IndexTerm>—a standard UNIX one, probably
109 <Literal>as</Literal><IndexTerm><Primary>as</Primary></IndexTerm>.
115 The <Emphasis>linker</Emphasis><IndexTerm><Primary>linker</Primary></IndexTerm>—a standard UNIX one, probably
116 <Literal>ld</Literal>.<IndexTerm><Primary>ld</Primary></IndexTerm>
122 A <Emphasis>runtime system</Emphasis>,<IndexTerm><Primary>runtime system</Primary></IndexTerm> including (most notably)
123 a storage manager; the linker links in the code for this.
129 The <Emphasis>Haskell standard prelude</Emphasis><IndexTerm><Primary>standard prelude</Primary></IndexTerm>, a
130 large library of standard functions, is linked in as well.
136 Parts of other <Emphasis>installed libraries</Emphasis> that you have at your site may be linked in also.
145 <Sect1 id="compile-what-really-happens">
146 <Title>What really happens when I “compile” a Haskell program?
150 You invoke the Glasgow Haskell compilation system through the
151 driver program <Literal>ghc</Literal>.<IndexTerm><Primary>ghc</Primary></IndexTerm> For example, if you had typed a
152 literate “Hello, world!” program into <Literal>hello.lhs</Literal>, and you then
162 the following would happen:
168 The file <Literal>hello.lhs</Literal> is run through the literate-program
169 code extractor <Literal>unlit</Literal><IndexTerm><Primary>unlit</Primary></IndexTerm>, feeding its output to
176 The Haskell compiler proper <Literal>hsc</Literal><IndexTerm><Primary>hsc</Primary></IndexTerm>, which produces
184 The assembler (or that ubiquitous “high-level assembler,” a C
185 compiler), which produces an object file and passes it to
192 The linker, which links your code with the appropriate libraries
193 (including the standard prelude), producing an executable program in
194 the default output file named <Literal>a.out</Literal>.
203 You have considerable control over the compilation process. You feed
204 command-line arguments (call them “options,” for short) to the
205 driver, <Literal>ghc</Literal>; the “types” of the input files (as encoded in
206 their names' suffixes) also matter.
210 Here's hoping this is enough background so that you can read the rest
216 <Sect1 id="mailing-lists-GHC">
217 <Title>Meta-information: Web sites, mailing lists, etc.
221 <IndexTerm><Primary>mailing lists, Glasgow Haskell</Primary></IndexTerm>
222 <IndexTerm><Primary>Glasgow Haskell mailing lists</Primary></IndexTerm>
226 On the World-Wide Web, there are several URLs of likely interest:
236 URL="http://www.haskell.org/"
237 >Haskell home page</ULink
245 URL="http://www.haskell.org/ghc/"
246 >GHC home page</ULink
254 URL="http://www.cs.nott.ac.uk/Department/Staff/mpj/faq.html"
255 >comp.lang.functional FAQ</ULink
265 We run two mailing lists about Glasgow Haskell. We encourage you to
266 join, as you feel is appropriate.
273 <Term>glasgow-haskell-users:</Term>
276 This list is for GHC users to chat among themselves. Subscribe by
277 sending mail to <email>majordomo@haskell.org</email>, with a message
278 body (not header) like this:
284 subscribe glasgow-haskell-users MyName <m.y.self@bigbucks.com>
290 (The last bit is your all-important e-mail address, of course.)
294 To communicate with your fellow users, send mail to <email>glasgow-haskell-users@haskell.org</email>.
298 To contact the list administrator, send mail to
299 <email>owner-glasgow-haskell-users@haskell.org</email>. An archive
300 of the list is available on the Web at the <ULink
301 URL="http://www.mail-archive.com/glasgow-haskell-users@haskell.org">glasgow-haskell-users
302 mailing list archive</ULink>.
307 <Term>glasgow-haskell-bugs:</Term>
310 Send bug reports for GHC to this address! The sad and lonely people
311 who subscribe to this list will muse upon what's wrong and what you
316 Subscribe via <email>majordomo@haskell.org</email> with:
322 subscribe glasgow-haskell-bugs My Name <m.y.self@hackers.r.us>
328 Again, you may contact the list administrator at <email>owner-glasgow-haskell-bugs@haskell.org</email>.
329 And, yes, an archive of the list is available on the Web at the <ULink
330 URL="http://www.mail-archive.com/glasgow-haskell-bugs@haskell.org">
331 glasgow-haskell-bugs mailing list archive</ULink
340 There is also the general Haskell mailing list. Subscribe by sending
341 email to <email>majordomo@haskell.org</email>, with the usual message body:
347 subscribe haskell My Name <m.y.self@fp.rules.ok.org>
353 Some Haskell-related discussion takes place in the Usenet newsgroup
354 <Literal>comp.lang.functional</Literal>.