List of commands
Here is an exhaustive, annotated list of GHCi commands, somewhat divided by task. Within each section, commands are listed alphabetically.
Some important ones are covered in more detail in their own lessons. Each command is linked to the page in this course that discusses it; you can either click through to find out about a particular command of interest, or keep reading through this series to get to it.
First, we start with the absolute basics.
:– The colon by itself repeats the previous command.
:help– Gives you some help.
:! <cmd>– Allows you to use shell commands, such as
pwdin ghci. This is also useful to people building tools on top of GHCi.
:cd– Changes the directory that
ghcihas access to.
:load <file>– Loads the specified file into the GHCi session. Without an argument, it unloads whatever had previously been loaded.
:main <args>– Runs a
mainwith some arguments.
:quit– Quit GHCi.
:reload– Does not take an argument. Reloads the current module, file, or project.
:set– This is used for many things; please see the article.
:set, but only affects commands typed at the GHCi prompt, not those loaded from a file.
:show language– Displays what language extensions are enabled.
:run <name> <args>– Similar to
Information about types and functions
Next you should become familiar with these commands for querying information about Haskell types and functions.
:doc <arg>– Show the documentation for a Haskell type, etc., right in the REPL.
:info– Queries information about a type, typeclass, value, function, or operator.
:instances– Shows a list of all typeclass instances that are available for a type.
:kind– Queries the kind of a type.
:type– Queries the type of a value or function.
Scope and availability
This set of commands is used for finding information about what’s in scope or changing what is in scope.
:add– Adds a module to the current target set and reloads.
:all-types– Lists all types for expressions and local bindings that are currently loaded.
:browse– Gives a list of the contents of a module (the module need not be imported).
:issafe <module>– Tells you the Safe Haskell information for a module (the current one if none is specified).
:module– Imports or de-imports modules. Can be used to expose an entire module, rather than only its exports.
:show bindings– Lists the definitions that have been entered at the GHCi command prompt.
:show imports– Lists the modules that are in scope.
:show modules– Lists the modules that are currently loaded.
:show packages– Lists packages that have been exposed via the
:show paths– Lists the files and directories in which GHCi will search for modules when you use
:show targets– Lists the modules in the target set
Debugging and evaluation
And here is a list of commands that are part of GHCi’s built-in debugging tools or useful for examining the evaluation of Haskell expressions.
:abandon– Abandons the current evaulation when stopped at a breakpoint.
:back <n>– Travel back
<n>steps in the history.
<n>is 1 when unspecified.
:break– Used to set a breakpoint.
:continue– Used to continue evaluation after a breakpoint.
:delete– Takes an argument: a number or
*. Deletes the specified number of breakpoints. If given
*, deletes all breakpoints. If you use the
:disablecommand instead of
:delete, you can restore the breakpoint using
:force <id>– Forces the printing of the identifier passed to it as an argument, forcing all the thunks along the way.
:forward <n>– Moves forward
<n>steps in the history.
<n>is 1 when unspecified.
:history <n>– Displays the history of the evaluation. If given a numeric argument, it displays that number of steps; otherwise, the default is 20.
:list <id>– Lists the source code around the definition of the identifier or the current breakpoint.
:print <id>– Prints a value without forcing its evaluation.
:sprint– Prints what has been evaluated so far while showing thunks with an underscore. Helpful for understanding laziness.
:step– Enables single-stepping through program evaluation. There is also
:trace <expr>– Traces evaluation of the expression and logs it for later inspection.
Advanced, less common
Most of these are not commonly used unless you are building something on top of GHCi or working on editor or IDE integration.
:ctags– Important for shaving certain Vi-style yaks.
:def– Takes arguments. Allows you to define custom GHCi commands and macros.
:edit <file>– Opens an editor to permit editing of a file, either the one passed to it as an argument or the currently loaded one.
:etags– This one is for the Emacs-flavored yaks.
:loc-at– Used for IDE and editor integration.
:script <file>– When given a filename as an argument, it executes the lines of code in that file as a series of GHCi commands.
:show– Prints a variety of information, most notably what GHC flags are enabled.
:show args– Shows what arguments have been set with
:set args, if any.
:type-at– Used for IDE and editor integration.
:undef– Undoes whatever you did with