GHCi commands all begin with
:’ and consist of a single command
name followed by zero or more parameters. The command name may be
abbreviated, with ambiguities being resolved in favour of the more
commonly used commands.
Abandons the current evaluation (only available when stopped at a breakpoint).
module(s) to the
current target set, and perform a
Travel back one step in the history. See Section 3.5.5, “Tracing and history”. See also:
Set a breakpoint on the specified function or line and column. See Section 184.108.40.206, “Setting breakpoints”.
Displays the identifiers defined by the module
module, which must be either
loaded into GHCi or be a member of a package. If
module is omitted, the most
recently-loaded module is used.
* symbol is placed before
the module name, then all the
identifiers in scope in
shown; otherwise the list is limited to the exports of
*-form is only available for modules
which are interpreted; for compiled modules (including
modules from packages) only the non-
:browse is available.
Changes the current working directory to
˜’ symbol at the
dir will be replaced
by the contents of the environment variable
NOTE: changing directories causes all currently loaded modules to be unloaded. This is because the search path is usually expressed using relative directories, and changing the search path in the middle of a session is not supported.
expr as a computation of
IO String, and then executes the resulting
string as a list of GHCi commands. Multiple commands are separated
by newlines. The
:cmd command is useful with
Continue the current evaluation, when stopped at a breakpoint.
Generates a “tags” file for Vi-style editors
Emacs-style editors (
no filename is specified, the default
used, respectively. Tags for all the functions, constructors and
types in the currently loaded modules are created. All modules must
be interpreted for these commands to work.
expr defines a new GHCi command
implemented by the Haskell expression
expr, which must have type
String -> IO String. When
: is typed at the
prompt, GHCi will run the expression
(, take the
String, and feed it back into
GHCi as a new sequence of commands. Separate commands in
the result must be separated by
That's all a little confusing, so here's a few examples. To start with, here's a new GHCi command which doesn't take any arguments or produce any results, it just outputs the current date & time:
Prelude> let date _ = Time.getClockTime >>= print >> return "" Prelude> :def date date Prelude> :date Fri Mar 23 15:16:40 GMT 2001
Here's an example of a command that takes an argument.
It's a re-implementation of
Prelude> let mycd d = Directory.setCurrentDirectory d >> return "" Prelude> :def mycd mycd Prelude> :mycd ..
Or I could define a simple way to invoke
ghc ––make Main” in the
Prelude> :def make (\_ -> return ":! ghc ––make Main")
We can define a command that reads GHCi input from a file. This might be useful for creating a set of bindings that we want to repeatedly load into the GHCi session:
Prelude> :def . readFile Prelude> :. cmds.ghci
Notice that we named the command
:., by analogy with the
.’ Unix shell command that
does the same thing.
:delete * |
Delete one or more breakpoints by number (use
breaks to see the number of each breakpoint). The
* form deletes all the breakpoints.
Opens an editor to edit the file
file, or the most recently loaded
file is omitted. The
editor to invoke is taken from the
environment variable, or a default editor on your system if
EDITOR is not set. You can change the
Prints the value of
the same way as
:force evaluates each
thunk that it encounters while traversing the value. This may
cause exceptions or infinite loops, or further breakpoints (which
are ignored, but displayed).
Move forward in the history. See Section 3.5.5, “Tracing and history”. See also:
Displays a list of the available commands.
Display the history of evaluation steps. With a number,
displays that many steps (default: 20). For use with
:trace; see Section 3.5.5, “Tracing and history”.
Displays information about the given name(s). For
name is a class, then
the class methods and their types will be printed; if
name is a type constructor, then
its definition will be printed; if
name is a function, then its type
will be printed. If
been loaded from a source file, then GHCi will also display
the location of its definition in the source.
For types and classes, GHCi also summarises instances that
mention them. To avoid showing irrelevant information, an instance
is shown only if (a) its head mentions
and (b) all the other things mentioned in the instance
are in scope (either qualified or otherwise) as a result of
Infers and prints the kind of
type. The latter can be an arbitrary
type expression, including a partial application of a type constructor,
Recursively loads the specified
modules, and all the modules they
depend on. Here, each
must be a module name or filename, but may not be the name
of a module in a package.
All previously loaded modules, except package modules,
are forgotten. The new set of modules is known as the
target set. Note that
:load can be used without any arguments
to unload all the currently loaded modules and
:load command, the current
context is set to:
module, if it was loaded
the most recently successfully loaded module, if
any other modules were loaded as a result of the current
When a program is compiled and executed, it can use the
getArgs function to access the
However, we cannot simply pass the arguments to the
main function while we are testing in ghci,
main function doesn't take its
Instead, we can use the
This runs whatever
main is in scope, with
any arguments being treated the same as command-line arguments,
Prelude> let main = System.Environment.getArgs >>= print Prelude> :main foo bar ["foo","bar"]
:module [+|-] [*],
Sets or modifies the current context for statements
typed at the prompt. The form
is equivalent to
See Section 3.4.3, “What's really in scope at the prompt?” for
Prints a value without forcing its evaluation.
to each thunk. See Section 3.5.1, “Breakpoints and inspecting variables” for more
information. See also the
which works like
Quits GHCi. You can also quit by typing control-D at the prompt.
Attempts to reload the current target set (see
:load) if any of the modules in the set,
or any dependent module, has changed. Note that this may
entail loading new modules, or dropping modules which are no
longer indirectly required by the target.
Sets various options. See Section 3.8, “The
for a list of available options. The
:set command by itself shows which
options are currently set.
Sets the command used by
Sets the string to be used as the prompt in GHCi.
prompt, the sequence
%s is replaced by the names of the
modules currently in scope, and
Set a command to be executed when a breakpoint is hit, or a new
item in the history is selected. The most common use of
:set stop is to display the source code at the
current location, e.g.
:set stop :list.
If a number is given before the command, then the commands are
run when the specified breakpoint (only) is hit. This can be quite
useful: for example,
:set stop 1 :continue
effectively disables breakpoint 1, by running
:continue whenever it is hit (although GHCi will
still emit a message to say the breakpoint was hit). What's more,
with cunning use of
:cmd you can use
:set stop to
implement conditional breakpoints:
*Main> :def cond \expr -> return (":cmd if (" ++ expr ++ ") then return \"\" else return \":continue\"") *Main> :set stop 0 :cond (x < 3)
Ignoring breakpoints for a specified number of iterations is also possible using similar techniques.
Show the bindings made at the prompt and their types.
List the active breakpoints.
List the active evaluations that are stopped at breakpoints.
Show the list of modules currently loaded.
Displays the specified setting (see
Prints a value without forcing its evaluation.
:sprint is similar to
Single-step from the last breakpoint. With an expression argument, begins evaluation of the expression with a single-step.
Evaluates the given expression (or from the last breakpoint if
no expression is given), and additionally logs the evaluation
steps for later inspection using
Section 3.5.5, “Tracing and history”.
Infers and prints the type of
expression, including explicit
forall quantifiers for polymorphic types. The monomorphism
restriction is not applied to the
expression during type inference.
Undefines the user-defined command
Unsets certain options. See Section 3.8, “The
for a list of available options.
Executes the shell command