Table of Contents
InstalledPackageInfo: a package specification
In this chapter you'll find a complete reference to the GHC command-line syntax, including all 400+ flags. It's a large and complex system, and there are lots of details, so it can be quite hard to figure out how to get started. With that in mind, this introductory section provides a quick introduction to the basic usage of GHC for compiling a Haskell program, before the following sections dive into the full syntax.
Let's create a Hello World program, and compile and run it.
First, create a file
the Haskell code:
main = putStrLn "Hello, World!"
To compile the program, use GHC like this:
$ ghc hello.hs
$ represents the prompt: don't
type it). GHC will compile the source
hello.hi, and then it
will link the object file to the libraries that come with GHC
to produce an executable called
By default GHC will be very quiet about what it is doing, only
printing error messages. If you want to see in more detail
what's going on behind the scenes, add
the command line.
Then we can run the program like this:
$ ./hello Hello World!
If your program contains multiple modules, then you only need to
tell GHC the name of the source file containing
Main module, and GHC will examine
import declarations to find the other
modules that make up the program and find their source files.
This means that, with the exception of
Main module, every source file should be
named after the module name that it contains (with dots replaced
by directory separators). For example, the
Data.Person would be in the
Data/Person.hs on Unix/Linux/Mac,
Data\Person.hs on Windows.