intro.sgml 12.9 KB
Newer Older
rrt's avatar
rrt committed
1 2 3 4 5 6 7 8 9
<Chapter id="introduction-GHC">
<Title>Introduction to GHC
</Title>

<Para>
This is a guide to using the Glasgow Haskell compilation (GHC) system. It is
a batch compiler for the Haskell&nbsp;98 language, with support for various
Glasgow-only extensions. In this document, we assume that GHC has been
installed at your site as <Literal>ghc</Literal>.  A separate document,
rrt's avatar
rrt committed
10
&ldquo;Building and Installing the Glasgow Functional Programming Tools Suite&rdquo;,
rrt's avatar
rrt committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
describes how to install <Literal>ghc</Literal>.
</Para>

<Para>
Many people will use GHC very simply: compile some
modules&mdash;<Literal>ghc -c -O Foo.hs Bar.hs</Literal>; and link them&mdash;
<Literal>ghc -o wiggle -O Foo.o Bar.o</Literal>.
</Para>

<Para>
But if you need to do something more complicated, GHC can do that,
too:

<Screen>
ghc -c -O -fno-foldr-build -dcore-lint -fvia-C -ddump-simpl Foo.lhs
</Screen>

Stay tuned&mdash;all will be revealed!
</Para>

<Para>
The rest of this section provide some tutorial information
on batch-style compilation; if you're familiar with these concepts
already, then feel free to skip to the next section.
</Para>

<Sect1 id="batch-system-parts">
<Title>The (batch) compilation system components</Title>

<Para>
The Glorious Haskell Compilation System, as with most UNIX (batch)
compilation systems, has several interacting parts:

<OrderedList>
<ListItem>
<Para>
47 48
A <Emphasis>driver</Emphasis><IndexTerm><Primary>driver
program</Primary></IndexTerm>
rrt's avatar
rrt committed
49
<Literal>ghc</Literal><IndexTerm><Primary>ghc</Primary></IndexTerm>&mdash;which
50 51 52 53
you usually think of as &ldquo;the compiler&rdquo;&mdash;is a program
that merely invokes/glues-together the other pieces of the system
(listed below), passing the right options to each, slurping in the
right libraries, etc.
rrt's avatar
rrt committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
</Para>
</ListItem>

<ListItem>
<Para>
A <Emphasis>literate pre-processor</Emphasis>
<IndexTerm><Primary>literate pre-processor</Primary></IndexTerm>
<IndexTerm><Primary>pre-processor, literate</Primary></IndexTerm>
<Literal>unlit</Literal><IndexTerm><Primary>unlit</Primary></IndexTerm> that extracts Haskell
code from a literate script; used if you believe in that sort of
thing.
</Para>
</ListItem>

<ListItem>
<Para>
The <Emphasis>Haskellised C pre-processor</Emphasis>
<IndexTerm><Primary>Haskellised C pre-processor</Primary></IndexTerm>
<IndexTerm><Primary>C pre-processor, Haskellised</Primary></IndexTerm>
<IndexTerm><Primary>pre-processor, Haskellised C</Primary></IndexTerm>
<Literal>hscpp</Literal>,<IndexTerm><Primary>hscpp</Primary></IndexTerm> only needed by people requiring conditional
rrt's avatar
rrt committed
75
compilation, probably for large systems.  The &ldquo;Haskellised&rdquo; part
rrt's avatar
rrt committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
just means that <Literal>&num;line</Literal> directives in the output have been
converted into proper Haskell <Literal>&lcub;-&num; LINE ... -&rcub;</Literal> pragmas. You must give an explicit <Literal>-cpp</Literal> option 
<IndexTerm><Primary>-cpp option</Primary></IndexTerm> for the C pre-processor to be invoked.
</Para>
</ListItem>

<ListItem>
<Para>
The <Emphasis>Haskell compiler</Emphasis>
<IndexTerm><Primary>Haskell compiler</Primary></IndexTerm>
<IndexTerm><Primary>compiler, Haskell</Primary></IndexTerm>
<Literal>hsc</Literal>,<IndexTerm><Primary>hsc</Primary></IndexTerm>
which&mdash;in normal use&mdash;takes its input from the C pre-processor
and produces assembly-language output (sometimes: ANSI C output).
</Para>
</ListItem>

<ListItem>
<Para>
The <Emphasis>ANSI&nbsp;C Haskell high-level assembler :-)</Emphasis>
<IndexTerm><Primary>ANSI C compiler</Primary></IndexTerm>
<IndexTerm><Primary>high-level assembler</Primary></IndexTerm>
<IndexTerm><Primary>assembler, high-level</Primary></IndexTerm>
compiles <Literal>hsc</Literal>'s C output into assembly language for a particular
target architecture.  In fact, the only C compiler we currently
support is <Literal>gcc</Literal>, because we make use of certain extensions to the
C language only supported by gcc.  Version 2.x is a must; we recommend
version 2.7.2.1 for stability (we've heard both good and bad reports
of later versions).
</Para>
</ListItem>

<ListItem>
<Para>
The <Emphasis>assembler</Emphasis><IndexTerm><Primary>assembler</Primary></IndexTerm>&mdash;a standard UNIX one, probably
<Literal>as</Literal><IndexTerm><Primary>as</Primary></IndexTerm>.
</Para>
</ListItem>

<ListItem>
<Para>
The <Emphasis>linker</Emphasis><IndexTerm><Primary>linker</Primary></IndexTerm>&mdash;a standard UNIX one, probably
<Literal>ld</Literal>.<IndexTerm><Primary>ld</Primary></IndexTerm>
</Para>
</ListItem>

<ListItem>
<Para>
A <Emphasis>runtime system</Emphasis>,<IndexTerm><Primary>runtime system</Primary></IndexTerm> including (most notably)
a storage manager; the linker links in the code for this.
</Para>
</ListItem>

<ListItem>
<Para>
The <Emphasis>Haskell standard prelude</Emphasis><IndexTerm><Primary>standard prelude</Primary></IndexTerm>, a
large library of standard functions, is linked in as well.
</Para>
</ListItem>

<ListItem>
<Para>
Parts of other <Emphasis>installed libraries</Emphasis> that you have at your site may be linked in also.
</Para>
</ListItem>

</OrderedList>
</Para>

</Sect1>

<Sect1 id="compile-what-really-happens">
rrt's avatar
rrt committed
148
<Title>What really happens when I &ldquo;compile&rdquo; a Haskell program?
rrt's avatar
rrt committed
149 150 151 152 153
</Title>

<Para>
You invoke the Glasgow Haskell compilation system through the
driver program <Literal>ghc</Literal>.<IndexTerm><Primary>ghc</Primary></IndexTerm> For example, if you had typed a
rrt's avatar
rrt committed
154
literate &ldquo;Hello, world!&rdquo; program into <Literal>hello.lhs</Literal>, and you then
rrt's avatar
rrt committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
invoked:

<Screen>
ghc hello.lhs
</Screen>

</Para>

<Para>
the following would happen:

<OrderedList>
<ListItem>

<Para>
The file <Literal>hello.lhs</Literal> is run through the literate-program
code extractor <Literal>unlit</Literal><IndexTerm><Primary>unlit</Primary></IndexTerm>, feeding its output to

</Para>
</ListItem>
<ListItem>

<Para>
The Haskell compiler proper <Literal>hsc</Literal><IndexTerm><Primary>hsc</Primary></IndexTerm>, which produces
input for

</Para>
</ListItem>
<ListItem>

<Para>
rrt's avatar
rrt committed
186
The assembler (or that ubiquitous &ldquo;high-level assembler,&rdquo; a C
rrt's avatar
rrt committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
compiler), which produces an object file and passes it to

</Para>
</ListItem>
<ListItem>

<Para>
The linker, which links your code with the appropriate libraries
(including the standard prelude), producing an executable program in
the default output file named <Literal>a.out</Literal>.
</Para>
</ListItem>

</OrderedList>

</Para>

<Para>
You have considerable control over the compilation process.  You feed
rrt's avatar
rrt committed
206 207
command-line arguments (call them &ldquo;options,&rdquo; for short) to the
driver, <Literal>ghc</Literal>; the &ldquo;types&rdquo; of the input files (as encoded in
rrt's avatar
rrt committed
208 209 210 211 212 213 214 215 216 217
their names' suffixes) also matter.
</Para>

<Para>
Here's hoping this is enough background so that you can read the rest
of this guide!
</Para>

</Sect1>

218 219
  <Sect1 id="mailing-lists-GHC">
    <Title>Meta-information: Web sites, mailing lists, etc.</Title>
rrt's avatar
rrt committed
220

221 222
    <IndexTerm><Primary>mailing lists, Glasgow Haskell</Primary></IndexTerm>
    <IndexTerm><Primary>Glasgow Haskell mailing lists</Primary></IndexTerm>
rrt's avatar
rrt committed
223

224 225
<Para>On the World-Wide Web, there are several URLs of likely
interest:</Para>
rrt's avatar
rrt committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

<Para>

<ItemizedList>
<ListItem>

<Para>
  <ULink
URL="http://www.haskell.org/"
>Haskell home page</ULink
>
</Para>
</ListItem>
<ListItem>

<Para>
  <ULink
URL="http://www.haskell.org/ghc/"
>GHC home page</ULink
>
</Para>
</ListItem>
<ListItem>

<Para>
  <ULink
URL="http://www.cs.nott.ac.uk/Department/Staff/mpj/faq.html"
>comp.lang.functional FAQ</ULink
>
</Para>
</ListItem>

</ItemizedList>

</Para>

<Para>
We run two mailing lists about Glasgow Haskell.  We encourage you to
join, as you feel is appropriate.
</Para>

<VariableList>
<VarListEntry>
<Term>glasgow-haskell-users:</Term>
<ListItem>
<Para>
272 273 274
This list is for GHC users to chat among themselves.  Subscription can
be done on-line at <ulink
url="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users"><literal>http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</literal></ulink>.</para>
rrt's avatar
rrt committed
275 276

<Para>
277
To communicate with your fellow users, send mail to <email>glasgow-haskell-users@haskell.org</email>.
rrt's avatar
rrt committed
278 279 280
</Para>

<Para>
281
To contact the list administrator, send mail to
282 283 284
<email>glasgow-haskell-users-admin@haskell.org</email>.  An archive
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>.

rrt's avatar
rrt committed
285 286 287 288 289 290 291 292 293 294 295 296
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term>glasgow-haskell-bugs:</Term>
<ListItem>
<Para>
Send bug reports for GHC to this address!  The sad and lonely people
who subscribe to this list will muse upon what's wrong and what you
might do about it.
</Para>

297 298
<para>Subscription can be done on-line at <ulink
url="http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs"><literal>http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs</literal></ulink>.</para>
rrt's avatar
rrt committed
299 300

<Para>
301 302 303
Again, you may contact the list administrator at
<email>glasgow-haskell-bugs-admin@haskell.org</email>.  And, yes, an
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>
rrt's avatar
rrt committed
304 305 306
</ListItem>
</VarListEntry>

307 308 309 310 311 312 313 314 315 316
	    <varlistentry>
	      <term>cvs-ghc:</term>
	      <listitem>
		<para>The hardcore GHC developers hang out here.  This
		list also gets commit message from the CVS repository.
		There are several other similar lists for other parts
		of the CVS repository
		(eg. <literal>cvs-hslibs</literal>,
		<literal>cvs-happy</literal>,
		<literal>cvs-hdirect</literal> etc.)</para>
rrt's avatar
rrt committed
317

318 319
		<para>To subscribe: <ulink
                url="http://www.haskell.org/mailman/listinfo/cvs-ghc"><literal>http://www.haskell.org/mailman/listinfo/cvs-ghc</literal></ulink></para>
rrt's avatar
rrt committed
320

321 322 323
	      </listitem>
	    </varlistentry>
	  </variablelist>
rrt's avatar
rrt committed
324

325 326 327 328 329
<Para>
There are several other haskell and GHC-related mailing lists served
by <literal>www.haskell.org</literal>.  Go to <ulink
url="http://www.haskell.org/mailman/listinfo/"><literal>http://www.haskell.org/mailman/listinfo/</literal></ulink>
for the full list.</Para>
rrt's avatar
rrt committed
330 331

<Para>
332 333
Some Haskell-related discussion also takes place in the Usenet
newsgroup <Literal>comp.lang.functional</Literal>.
rrt's avatar
rrt committed
334 335
</Para>

336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
  </Sect1>

  <sect1 id="version-numbering">
    <title>GHC version numbering policy</title>
    <indexterm><primary>version, of ghc</primary></indexterm>

    <para>As of GHC version 4.08, we have adopted the following
    policy for numbering GHC versions:</para>

    <variablelist>
      <varlistentry>
	<term>Stable Releases</term>
	<listitem>
	  <para>These are numbered <literal>x.yy.z</literal>, where
	  <literal>yy</literal> is <emphasis>even</emphasis>, and
	  <literal>z</literal> is the patchlevel number (the trailing
	  <literal>.z</literal> can be omitted if <literal>z</literal>
	  is zero).  Patchlevels are bug-fix releases only, and never
	  change the programmer interface to any system-supplied code.
	  However, if you install a new patchlevel over an old one you
	  may need to recompile any code that was compiled against the
	  old libraries.</para>

	  <para>The value of <literal>__GLASGOW_HASKELL__</literal>
	  (see <xref linkend="c-pre-processor">) for a major release
	  <literal>x.yy.z</literal> is the integer
	  <literal>xyy</literal>.</para>
	  <indexterm>
	    <primary><literal>__GLASGOW_HASKELL__</literal></primary>
	  </indexterm>
	</listitem>
      </varlistentry>
      
      <varlistentry>
	<term>Snapshots/unstable releases</term>
	<listitem>
	  <para>We may make snapshot releases of the current
	  development sources from time to time, and the current
	  sources are always available via the CVS repository (see the
	  GHC web site for details).</para>

	  <para>Snapshot releases are named
378 379
	  <literal>x.yy.YYYYMMDD</literal> where <literal>yy</literal>
	  is <emphasis>odd</emphasis>, and <literal>YYYYMMDD</literal>
380 381 382 383 384 385 386 387 388 389
	  is the date of the sources from which the snapshot was
	  built.  In theory, you can check out the exact same sources
	  from the CVS repository using this date.</para>

	  <para>The value of <literal>__GLASGOW_HASKELL__</literal>
	  for a snapshot release is the integer
	  <literal>xyy</literal>.  You should never write any
	  conditional code which tests for this value, however: since
	  interfaces change on a day-to-day basis, and we don't have
	  finer granularity in the values of
390
	  <literal>__GLASGOW_HASKELL__</literal>, you should only
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
	  conditionally compile using predicates which test whether
	  <literal>__GLASGOW_HASKELL__</literal> is equal to, later
	  than, or earlier than a given major release.</para>
	  <indexterm>
	    <primary><literal>__GLASGOW_HASKELL__</literal></primary>
	  </indexterm>
	</listitem>
      </varlistentry>
    </variablelist>
    
    <para>The version number of your copy of GHC can be found by
    invoking <literal>ghc</literal> with the
    <literal>--version</literal> flag.</para>
  </sect1>

rrt's avatar
rrt committed
406 407 408 409

&relnotes

</Chapter>
410 411 412 413 414 415 416

<!-- Emacs stuff:
     ;;; Local Variables: ***
     ;;; mode: sgml ***
     ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***
     ;;; End: ***
 -->