This is a guide to using the Glasgow Haskell compilation (GHC) system. It is a batch compiler for the Haskell 98 language, with support for various Glasgow-only extensions. In this document, we assume that GHC has been installed at your site as ghc. A separate document, “Building and Installing the Glasgow Functional Programming Tools Suite”, describes how to install ghc.
Many people will use GHC very simply: compile some modules—ghc -c -O Foo.hs Bar.hs; and link them— ghc -o wiggle -O Foo.o Bar.o.
But if you need to do something more complicated, GHC can do that, too:
ghc -c -O -fno-foldr-build -dcore-lint -fvia-C -ddump-simpl Foo.lhs |
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.
The Glorious Haskell Compilation System, as with most UNIX (batch) compilation systems, has several interacting parts:
A driver ghc—which you usually think of as “the compiler”—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.
A literate pre-processor unlit that extracts Haskell code from a literate script; used if you believe in that sort of thing.
The Haskellised C pre-processor hscpp, only needed by people requiring conditional compilation, probably for large systems. The “Haskellised” part just means that #line directives in the output have been converted into proper Haskell {-# LINE ... -} pragmas. You must give an explicit -cpp option for the C pre-processor to be invoked.
The Haskell compiler hsc, which—in normal use—takes its input from the C pre-processor and produces assembly-language output (sometimes: ANSI C output).
The ANSI C Haskell high-level assembler :-) compiles hsc's C output into assembly language for a particular target architecture. In fact, the only C compiler we currently support is gcc, 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).
The assembler—a standard UNIX one, probably as.
The linker—a standard UNIX one, probably ld.
A runtime system, including (most notably) a storage manager; the linker links in the code for this.
The Haskell standard prelude, a large library of standard functions, is linked in as well.
Parts of other installed libraries that you have at your site may be linked in also.