Chapter 3. Using GHC

Table of Contents
3.1. Overall command-line structure
3.2. Meaningful file suffixes
3.3. Help and verbosity options
3.4. Running the right phases in the right order
3.5. Re-directing the compilation output(s)
3.6. Warnings and sanity-checking
3.7. Separate compilation
3.8. Optimisation (code improvement)
3.9. Options related to a particular phase
3.10. Using Concurrent Haskell
3.11. Using Parallel Haskell
3.12. Running a compiled program
3.13. Debugging the compiler

GHC is a command-line compiler: in order to compile a Haskell program, GHC must be invoked on the source file(s) by typing a command to the shell. The steps involved in compiling a program can be automated using the make tool (this is especially useful if the program consists of multiple source files which depend on each other). This section describes how to use GHC from the command-line.

3.1. Overall command-line structure

An invocation of GHC takes the following form:

ghc [argument...]

Command-line arguments are either options or file names.

Command-line options begin with -. They may not be grouped: -vO is different from -v -O. Options need not precede filenames: e.g., ghc *.o -o foo. All options are processed and then applied to all files; you cannot, for example, invoke ghc -c -O1 Foo.hs -O2 Bar.hs to apply different optimisation levels to the files Foo.hs and Bar.hs. For conflicting options, e.g., -c -S, we reserve the right to do anything we want. (Usually, the last one applies.)