Skip to content

Customizing the GHCi Prompt (Optional)

By default, the prompt in GHCi tells you which modules—similar to packages in Java—you have loaded.1 The prompt you see when starting GHCi,

GHCi
Prelude> █

tells you that the Haskell prelude has been loaded. The prelude is a package that provides a substantial portion of the Haskell standard library, the most commonly used functions. Since you will use many of them in any piece of non-trivial Haskell code you will write, it is loaded automatically when you start GHCi. It is also imported automatically into any program you compile using GHC. This happens without you having to specify explicitly that you want to import the prelude.

Knowing which modules are loaded, so you can use the functions they provide at the GHCi prompt, is useful, but the listing of these modules can become long if you load many modules:

GHCi
Prelude> import Data.List
Prelude Data.List> import Control.Monad
Prelude Data.List Control.Monad> import Data.Bifunctor
Prelude Data.List Control.Monad Data.Bifunctor> import Data.Maybe
Prelude Data.List Control.Monad Data.Bifunctor Data.Maybe> import System.IO
Prelude Data.List Control.Monad Data.Bifunctor Data.Maybe System.IO> █

To reduce the clutter, many Haskellers prefer to customize their prompt to something shorter. I personally use >>>, the same prompt used by the Python interpreter when used interactively.

To get the prompt I use—you can choose whatever you want or leave the prompt as it is if you prefer—use the command:

GHCi
Prelude> :set prompt ">>> "
>>> █

(Note, this needs to be run from inside GHCi, so you need to start it using stack ghci first.)

If you want the prompt to be set automatically every time you start ghci, then you need to add the above command to GHCi's init file in your home directory:

~/.ghci
:set prompt ">>> "

In fact, my .ghci file looks like this:

~/.ghci
:set prompt ">>> "
:set prompt-cont "  | "

This also customizes the prompt of continuation lines when entering multi-line expressions; more about those in a later section.

Customizing the GHCi prompt is not important, but I will use the >>> prompt from here on in this book, so I thought it important that you know why it looks different from your prompt if you choose not to customize your prompt.


  1. Haskell also has a notion of packages that is different from modules. I'll comment on modules and packages in detail later.