GHCi is invoked with the command
ghc ––interactive. One or more modules or
filenames can also be specified on the command line; this
instructs GHCi to load the specified modules or filenames (and all
the modules they depend on), just as if you had said
:load at the
GHCi prompt (see Section 2.7, “GHCi commands”). For example, to
start GHCi and load the program whose topmost module is in the
Main.hs, we could say:
$ ghci Main.hs
Most of the command-line options accepted by GHC (see Chapter 4, Using GHC) also make sense in interactive mode. The ones that don't make sense are mostly obvious.
Most packages (see Section 4.9.1, “Using Packages ”) are available without needing to specify any extra flags at all: they will be automatically loaded the first time they are needed.
For hidden packages, however, you need to request the
package be loaded by using the
$ ghci -package readline GHCi, version 6.8.1: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Loading package readline-1.0 ... linking ... done. Prelude>
The following command works to load new packages into a running GHCi:
Prelude> :set -package
But note that doing this will cause all currently loaded
modules to be unloaded, and you'll be dumped back into the
Extra libraries may be specified on the command line using
option. (The term library here refers to
libraries of foreign object code; for using libraries of Haskell
source code, see Section 2.2.1, “Modules vs. filenames”.) For
example, to load the “m” library:
$ ghci -lm
On systems with
libraries, the actual library loaded will the
searches the following places for libraries, in this order:
Paths specified using the
the standard library search path for your system,
which on some systems may be overridden by setting the
On systems with
libraries, the actual library loaded will be
GHCi will signal an error if it can't find the library.
GHCi can also load plain object files
.obj depending on
your platform) from the command-line. Just add the name the
object file to the command line.
-l options matters: a library
should be mentioned before the libraries it
depends on (see Section 4.11.6, “Options affecting linking”).