3.5. Invoking GHCi

GHCi is invoked with the command ghci or ghc --interactive. A module or filename can also be specified on the command line; this instructs GHCi to load the that module or filename (and all the modules it depends on), just as if you had said :load module at the GHCi prompt (see Section 3.6). For example, to start GHCi and load the program whose topmost module is in the file Main.hs, we could say:

$ ghci Main.hs

Note: only one module name or filename may be given on the command line.

Most of the command-line options accepted by GHC (see Chapter 4) also make sense in interactive mode. The ones that don't make sense are mostly obvious; for example, GHCi doesn't generate interface files, so options related to interface file generation won't have any effect.

3.5.1. Packages

GHCi can make use of all the packages that come with GHC, but note: packages must be specified on the GHCi command line, you can't add extra packages after GHCi has started up. For example, to start up GHCi with the text package loaded:

$ ghci -package text
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 5.00, For Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package std ... linking ... done.
Loading package lang ... linking ... done.
Loading package text ... linking ... done.
Prelude> 

Note that GHCi also loaded the lang package even though we didn't ask for it: that's because the text package makes use of one or more of the modules in lang, and therefore has a dependency on it.

3.5.2. Extra libraries

Extra libraries may be specified on the command line using the normal -llib option. For example, to load the “m” library:

$ ghci -lm

On systems with .so-style shared libraries, the actual library loaded will the liblib.so. If no such library exists on the standard library search path, including paths given using -Lpath, then ghci will signal an error.

On systems with .dll-style shared libraries, the actual library loaded will be lib.dll. Again, GHCi will signal an error if it can't find the library.