1 <sect>Introduction to GHC
2 <label id="introduction-GHC">
5 This is a guide to using the Glasgow Haskell compilation (GHC) system.
6 It is a batch compiler for the Haskell~98 language, with support for
7 various Glasgow-only extensions.
8 In this document, we assume that GHC has been installed at your site
9 as @ghc@. A separate document, ``Building and Installing the
10 Glasgow Functional Programming Tools Suite'',
11 describes how to install @ghc@.
13 Many people will use GHC very simply: compile some
14 modules---@ghc -c -O Foo.hs Bar.hs@; and link them---
15 @ghc -o wiggle -O Foo.o Bar.o@.
17 But if you need to do something more complicated, GHC can do that,
20 ghc -c -O -fno-foldr-build -dcore-lint -fvia-C -ddump-simpl Foo.lhs
22 Stay tuned---all will be revealed!
24 The rest of this section provide some tutorial information
25 on batch-style compilation; if you're familiar with these concepts
26 already, then feel free to skip to the next section.
28 %************************************************************************
30 <sect1>The (batch) compilation system components
31 <label id="batch-system-parts">
34 %************************************************************************
36 The Glorious Haskell Compilation System, as with most UNIX (batch)
37 compilation systems, has several interacting parts:
40 A <em>driver</em><nidx>driver program</nidx> @ghc@<nidx>ghc</nidx>---which you
41 usually think of as ``the compiler''---is a program that merely
42 invokes/glues-together the other pieces of the system (listed below),
43 passing the right options to each, slurping in the right libraries,
47 A <em>literate pre-processor</em>
48 <nidx>literate pre-processor</nidx>
49 <nidx>pre-processor, literate</nidx>
50 @unlit@<nidx>unlit</nidx> that extracts Haskell
51 code from a literate script; used if you believe in that sort of
55 The <em>Haskellised C pre-processor</em>
56 <nidx>Haskellised C pre-processor</nidx>
57 <nidx>C pre-processor, Haskellised</nidx>
58 <nidx>pre-processor, Haskellised C</nidx>
59 @hscpp@,<nidx>hscpp</nidx> only needed by people requiring conditional
60 compilation, probably for large systems. The ``Haskellised'' part
61 just means that @#line@ directives in the output have been
62 converted into proper Haskell @{-# LINE ... -@} pragmas.
64 You must give an explicit @-cpp@ option
65 <nidx>-cpp option</nidx> for the C pre-processor to be invoked.
68 The <em>Haskell compiler</em>
69 <nidx>Haskell compiler</nidx>
70 <nidx>compiler, Haskell</nidx>
71 @hsc@,<nidx>hsc</nidx>
72 which---in normal use---takes its input from the C pre-processor
73 and produces assembly-language output (sometimes: ANSI C output).
76 The <em>ANSI~C Haskell high-level assembler :-)</em>
77 <nidx>ANSI C compiler</nidx>
78 <nidx>high-level assembler</nidx>
79 <nidx>assembler, high-level</nidx>
81 compiles @hsc@'s C output into assembly language for a particular
82 target architecture. In fact, the only C compiler we currently
83 support is <tt/gcc/, because we make use of certain extensions to the
84 C language only supported by gcc. Version 2.x is a must; we recommend
85 version 2.7.2.1 for stability (we've heard both good and bad reports
89 The <em>assembler</em><nidx>assembler</nidx>---a standard UNIX one, probably
93 The <em>linker</em><nidx>linker</nidx>---a standard UNIX one, probably
97 A <em>runtime system</em>,<nidx>runtime system</nidx> including (most notably)
98 a storage manager; the linker links in the code for this.
101 The <em>Haskell standard prelude</em><nidx>standard prelude</nidx>, a
102 large library of standard functions, is linked in as well.
105 Parts of other <em>installed libraries</em> that you have at your site
106 may be linked in also.
109 %************************************************************************
111 <sect1>What really happens when I ``compile'' a Haskell program?
112 <label id="compile-what-really-happens">
115 %************************************************************************
117 You invoke the Glasgow Haskell compilation system through the
118 driver program @ghc@.<nidx>ghc</nidx> For example, if you had typed a
119 literate ``Hello, world!'' program into @hello.lhs@, and you then
125 the following would happen:
128 The file @hello.lhs@ is run through the literate-program
129 code extractor @unlit@<nidx>unlit</nidx>, feeding its output to
132 The Haskell compiler proper @hsc@<nidx>hsc</nidx>, which produces
136 The assembler (or that ubiquitous ``high-level assembler,'' a C
137 compiler), which produces an object file and passes it to
140 The linker, which links your code with the appropriate libraries
141 (including the standard prelude), producing an executable program in
142 the default output file named @a.out@.
145 You have considerable control over the compilation process. You feed
146 command-line arguments (call them ``options,'' for short) to the
147 driver, @ghc@; the ``types'' of the input files (as encoded in
148 their names' suffixes) also matter.
150 Here's hoping this is enough background so that you can read the rest
153 % The ``style'' of the driver program @ghc@ follows that of the GNU C
154 % compiler driver @gcc@. The use of environment variables to provide
155 % defaults is more extensive in this compilation system.
157 %--------------------------------------------------------------------
158 <sect1>Meta-information: Web sites, mailing lists, etc.
159 <label id="mailing-lists-GHC">
161 <nidx>mailing lists, Glasgow Haskell</nidx>
162 <nidx>Glasgow Haskell mailing lists</nidx>
164 On the World-Wide Web, there are several URLs of likely interest:
167 <item> <url name="Haskell home page" url="http://www.haskell.org/">
168 <item> <url name="GHC home page" url="http://www.haskell.org/ghc/">
169 <item> <url name="Glasgow FP group page" url="http://www.dcs.gla.ac.uk/fp/">
170 <item> <url name="comp.lang.functional FAQ" url="http://www.cs.nott.ac.uk/Department/Staff/mpj/faq.html">
173 We run two mailing lists about Glasgow Haskell. We encourage you to
174 join, as you feel is appropriate.
178 <tag>glasgow-haskell-users:</tag>
180 This list is for GHC users to chat among themselves. Subscribe by
181 sending mail to <htmlurl name="majordomo@@haskell.org"
182 url="mailto:majordomo@@haskell.org">, with a message body (not
186 subscribe glasgow-haskell-users MyName <m.y.self@@bigbucks.com>
189 (The last bit is your all-important e-mail address, of course.)
191 To communicate with your fellow users, send mail to <url
192 name="glasgow-haskell-users@@haskell.org"
193 url="mailto:glasgow-haskell-users@@haskell.org">.
195 To contact the list administrator, send mail to <htmlurl
196 name="glasgow-haskell-users-request@@haskell.org"
197 url="mailto:glasgow-haskell-users-request@@haskell.org">. An archive
198 of the list is available on the Web: <url name="glasgow-haskell-users
199 mailing list archive"
200 url="http://www.dcs.gla.ac.uk/mail-www/glasgow-haskell-users">.
202 <tag>glasgow-haskell-bugs:</tag>
203 Send bug reports for GHC to this address! The sad and lonely people
204 who subscribe to this list will muse upon what's wrong and what you
207 Subscribe via <htmlurl name="majordomo@@haskell.org"
208 url="mailto:majordomo@@haskell.org"> with:
211 subscribe glasgow-haskell-bugs My Name <m.y.self@@hackers.r.us>
214 Again, you may contact the list administrator at <htmlurl
215 name="glasgow-haskell-bugs-request@@haskell.org"
216 url="mailto:glasgow-haskell-bugs-request@@haskell.org">.
217 And, yes, an archive of the list is available on the Web at: : <url
218 name="glasgow-haskell-bugs mailing list archive"
219 url="http://www.dcs.gla.ac.uk/mail-www/glasgow-haskell-bugs">
223 There is also the general Haskell mailing list. Subscribe by sending
224 email to <htmlurl name="majordomo@@dcs.gla.ac.uk"
225 url="mailto:majordomo@@dcs.gla.ac.uk">, with the usual message body:
228 subscribe haskell My Name <m.y.self@@fp.rules.ok.org>
231 Some Haskell-related discussion takes place in the Usenet newsgroup
232 @comp.lang.functional@. (But note: news is basically dead at Glasgow.
233 That's one reason Glaswegians aren't too active in c.f.l.)
235 The main anonymous-FTP site for Glasgow Haskell is <htmlurl
236 name="ftp://ftp.dcs.gla.ac.uk/pub/haskell/glasgow"
237 url="ftp://ftp.dcs.gla.ac.uk/pub/haskell/glasgow">. ``Important''
238 bits are mirrored at other Haskell archive sites (and we have their