In your GHCi configuration GHC User’s Guide: The
.ghci files (sometimes called your “dot ghci file”), you can write GHCi commands that will run automatically every time you start GHCi.
Config file locations
GHCi reads config files from the following locations:
- Depending on the OS:
- Linux and macOS:
C:\Documents and Settings\<username>\Application Data/ghc/ghci.conf
- Linux and macOS:
If more than one of these is present, then GHCi will run them all, in the order given above.
The first path
./.ghci is relative to the current directory, so it can be useful for project-specific options. The latter two are where you keep configuration that you will use all the time. You can choose to put your configuration in either location, according to your preference.
Customizing your prompt
By default, the GHCi prompt looks like this:
It shows you what modules are imported, followed by
> on the first line of each command, and
| on any subsequent lines of a multi-line command. Often the module list ends up being obstrusively long, and so many people choose to set a different prompt. A popular choice is
λ>. You can do this by setting the
prompt-cont variables in your GHCi config:
Now your prompt will look like this:
You can also use ANSI escape codes to apply color. For example, to turn the prompt purple:
Enabling language extensions
You can enable and disable GHC language extensions on the fly as you need them, but for extensions that you use very often, you may want to consider modifying your config to enable them by default.
For example, you might add something like this to your dot GHCi file, to enable these common basic extensions: See our recommended list of extensions for beginners.
Disabling GHCi config
If you want to start a clean, standard GHCi that is unaffected by any configuration files, start GHCi with the
If you’re starting GHCi with Stack, it will look like this:
Reading the source
If you’re curious about the details of how GHCi finds its config files, you can look at the source code for GHCi, which is located within the
ghc git repository.
getAppUserDataDirectoryInternal has a different implementation depending on what operating system the package is built for. On a Unix platform, it looks like this:
And on Windows, it looks like this:
You can try using this function yourself and see what it returns for your system:
For historical reasons, GHCi does not follow the XDG Base Directory Specification,XDG specifies a set of conventions for file paths. It has the advantage of allowing users to customize paths using environment variables, rather than forcing users to keep files in a particular location dictated by the program. but it is recommended that you do so for new programs that you are writing. The
directory package supports this as well: Use
getXdgDirectory instead of