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~1.4 language, with support for
7 various Glasgow-only extensions.
9 Many people will use GHC very simply: compile some
10 modules---@ghc -c -O Foo.hs Bar.hs@; and link them---
11 @ghc -o wiggle -O Foo.o Bar.o@.
13 But if you need to do something more complicated, GHC can do that,
16 ghc -c -O -fno-foldr-build -dcore-lint -fvia-C -ddump-simpl Foo.lhs
18 Stay tuned---all will be revealed!
20 In this document, we assume that GHC has been installed at your site
21 as @ghc@. The rest of this section provide some tutorial information
22 on batch-style compilation; if you're familiar with these concepts
23 already, then feel free to skip to the next section.
25 %************************************************************************
27 <sect1>The (batch) compilation system components
28 <label id="batch-system-parts">
31 %************************************************************************
33 The Glorious Haskell Compilation System, as with most UNIX (batch)
34 compilation systems, has several interacting parts:
37 A <em>driver</em><nidx>driver program</nidx> @ghc@<nidx>ghc</nidx>---which you
38 usually think of as ``the compiler''---is a program that merely
39 invokes/glues-together the other pieces of the system (listed below),
40 passing the right options to each, slurping in the right libraries,
44 A <em>literate pre-processor</em>
45 <nidx>literate pre-processor</nidx>
46 <nidx>pre-processor, literate</nidx>
47 @unlit@<nidx>unlit</nidx> that extracts Haskell
48 code from a literate script; used if you believe in that sort of
52 The <em>Haskellised C pre-processor</em>
53 <nidx>Haskellised C pre-processor</nidx>
54 <nidx>C pre-processor, Haskellised</nidx>
55 <nidx>pre-processor, Haskellised C</nidx>
56 @hscpp@,<nidx>hscpp</nidx> only needed by people requiring conditional
57 compilation, probably for large systems. The ``Haskellised'' part
58 just means that @#line@ directives in the output have been
59 converted into proper Haskell @{-# LINE ... -@} pragmas.
61 You must give an explicit @-cpp@ option
62 <nidx>-cpp option</nidx> for the C pre-processor to be invoked.
65 The <em>Haskell compiler</em>
66 <nidx>Haskell compiler</nidx>
67 <nidx>compiler, Haskell</nidx>
68 @hsc@,<nidx>hsc</nidx>
69 which---in normal use---takes its input from the C pre-processor
70 and produces assembly-language output (sometimes: ANSI C output).
73 The <em>ANSI~C Haskell high-level assembler :-)</em>
74 <nidx>ANSI C compiler</nidx>
75 <nidx>high-level assembler</nidx>
76 <nidx>assembler, high-level</nidx>
78 compiles @hsc@'s C output into assembly language for a particular
79 target architecture. In fact, the only C compiler we currently
80 support is <tt/gcc/, because we make use of certain extensions to the
81 C language only supported by gcc. Version 2.x is a must; we recommend
82 version 2.7.2.1 for stability (we've heard both good and bad reports
86 The <em>assembler</em><nidx>assembler</nidx>---a standard UNIX one, probably
90 The <em>linker</em><nidx>linker</nidx>---a standard UNIX one, probably
94 A <em>runtime system</em>,<nidx>runtime system</nidx> including (most notably)
95 a storage manager; the linker links in the code for this.
98 The <em>Haskell standard prelude</em><nidx>standard prelude</nidx>, a
99 large library of standard functions, is linked in as well.
102 Parts of other <em>installed libraries</em> that you have at your site
103 may be linked in also.
106 %************************************************************************
108 <sect1>What really happens when I ``compile'' a Haskell program?
109 <label id="compile-what-really-happens">
112 %************************************************************************
114 You invoke the Glasgow Haskell compilation system through the
115 driver program @ghc@.<nidx>ghc</nidx> For example, if you had typed a
116 literate ``Hello, world!'' program into @hello.lhs@, and you then
122 the following would happen:
125 The file @hello.lhs@ is run through the literate-program
126 code extractor @unlit@<nidx>unlit</nidx>, feeding its output to
129 The Haskell compiler proper @hsc@<nidx>hsc</nidx>, which produces
133 The assembler (or that ubiquitous ``high-level assembler,'' a C
134 compiler), which produces an object file and passes it to
137 The linker, which links your code with the appropriate libraries
138 (including the standard prelude), producing an executable program in
139 the default output file named @a.out@.
142 You have considerable control over the compilation process. You feed
143 command-line arguments (call them ``options,'' for short) to the
144 driver, @ghc@; the ``types'' of the input files (as encoded in
145 their names' suffixes) also matter.
147 Here's hoping this is enough background so that you can read the rest
150 % The ``style'' of the driver program @ghc@ follows that of the GNU C
151 % compiler driver @gcc@. The use of environment variables to provide
152 % defaults is more extensive in this compilation system.
154 %--------------------------------------------------------------------
155 <sect1>Meta-information: Web sites, mailing lists, etc.
156 <label id="mailing-lists-GHC">
158 <nidx>mailing lists, Glasgow Haskell</nidx>
159 <nidx>Glasgow Haskell mailing lists</nidx>
161 On the World-Wide Web, there are several URLs of likely interest:
164 <item> <url name="Haskell home page" url="http://haskell.org/">
165 <item> <url name="GHC home page" url="http://www.dcs.gla.ac.uk/fp/software/ghc/">
166 <item> <url name="Glasgow FP group page" url="http://www.dcs.gla.ac.uk/fp/">
167 <item> <url name="comp.lang.functional FAQ" url="http://www.cs.nott.ac.uk/Department/Staff/mpj/faq.html">
170 We run two mailing lists about Glasgow Haskell. We encourage you to
171 join, as you feel is appropriate.
175 <tag>glasgow-haskell-users:</tag>
177 This list is for GHC users to chat among themselves. Subscribe by
178 sending mail to <htmlurl name="majordomo@@dcs.gla.ac.uk"
179 url="mailto:majordomo@@dcs.gla.ac.uk">, with a message body (not
183 subscribe glasgow-haskell-users MyName <m.y.self@@bigbucks.com>
186 (The last bit is your all-important e-mail address, of course.)
188 To communicate with your fellow users, send mail to <url
189 name="glasgow-haskell-users@@dcs.gla.ac.uk"
190 url="mailto:glasgow-haskell-users@@dcs.gla.ac.uk">.
192 To contact the list administrator, send mail to <htmlurl
193 name="glasgow-haskell-users-request@@dcs.gla.ac.uk"
194 url="mailto:glasgow-haskell-users-request@@dcs.gla.ac.uk">. An archive
195 of the list is available on the Web: <url name="glasgow-haskell-users
196 mailing list archive"
197 url="http://www.dcs.gla.ac.uk/mail-www/glasgow-haskell-users">.
199 <tag>glasgow-haskell-bugs:</tag>
200 Send bug reports for GHC to this address! The sad and lonely people
201 who subscribe to this list will muse upon what's wrong and what you
204 Subscribe via <htmlurl name="majordomo@@dcs.gla.ac.uk"
205 url="mailto:majordomo@@dcs.gla.ac.uk"> with:
208 subscribe glasgow-haskell-bugs My Name <m.y.self@@hackers.r.us>
211 Again, you may contact the list administrator at <htmlurl
212 name="glasgow-haskell-bugs-request@@dcs.gla.ac.uk"
213 url="mailto:glasgow-haskell-bugs-request@@dcs.gla.ac.uk">.
214 And, yes, an archive of the list is available on the Web at: : <url
215 name="glasgow-haskell-bugs mailing list archive"
216 url="http://www.dcs.gla.ac.uk/mail-www/glasgow-haskell-bugs">
220 There is also the general Haskell mailing list. Subscribe by sending
221 email to <htmlurl name="majordomo@@dcs.gla.ac.uk"
222 url="mailto:majordomo@@dcs.gla.ac.uk">, with the usual message body:
225 subscribe haskell My Name <m.y.self@@fp.rules.ok.org>
228 Some Haskell-related discussion takes place in the Usenet newsgroup
229 @comp.lang.functional@. (But note: news is basically dead at Glasgow.
230 That's one reason Glaswegians aren't too active in c.f.l.)
232 The main anonymous-FTP site for Glasgow Haskell is <htmlurl
233 name="ftp://ftp.dcs.gla.ac.uk/pub/haskell/glasgow"
234 url="ftp://ftp.dcs.gla.ac.uk/pub/haskell/glasgow">. ``Important''
235 bits are mirrored at other Haskell archive sites (and we have their