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.

Basics

First, we start with the absolute basics.

  • : – The colon by itself repeats the previous command.
  • :? or :help – Gives you some help.
  • :! <cmd> – Allows you to use shell commands, such as pwd in ghci. This is also useful to people building tools on top of GHCi.
  • :cd – Changes the directory that ghci has 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 main with 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.
  • :seti – Like :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 :main.
  • :unset – Undoes :set.

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 -package flag.
  • :show paths – Lists the files and directories in which GHCi will search for modules when you use :load.
  • :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 :disable command instead of :delete, you can restore the breakpoint using :enable.
  • :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.
  • :show stop
  • :show breaks
  • :show context
  • :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 :steplocal and :stepmodule.
  • :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.

  • :cmd
  • :complete
  • :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.
  • :show editor
  • :show linker
  • :show prog
  • :type-at – Used for IDE and editor integration.
  • :undef – Undoes whatever you did with :def.
  • :uses

Join Type Classes for courses and projects to get you started and make you an expert in FP with Haskell.