3.8. The .ghci file

When it starts, GHCi always reads and executes commands from $HOME/.ghci, followed by ./.ghci.

The .ghci in your home directory is most useful for turning on favourite options (eg. :set +s), and defining useful macros. Placing a .ghci file in a directory with a Haskell project is a useful way to set certain project-wide options so you don't have to type them everytime you start GHCi: eg. if your project uses GHC extensions and CPP, and has source files in three subdirectories A B and C, you might put the following lines in .ghci:

:set -fglasgow-exts -cpp
:set -iA:B:C

(Note that strictly speaking the -i flag is a static one, but in fact it works to set it using :set like this. The changes won't take effect until the next :load, though.)

Two command-line options control whether the .ghci files are read:


Don't read either ./.ghci or $HOME/.ghci when starting up.


Read .ghci and $HOME/.ghci. This is normally the default, but the -read-dot-ghci option may be used to override a previous -ignore-dot-ghci option.