1
votes

In my cabal file I have a bunch of language extensions enabled. Let's say I have

  • TemplateHaskell
  • QuasiQuotes
  • CPP

Is there a way to start GHCi with these enabled automatically? instead of manually doing

ghci -XTemplateHaskell -XQuasiQuotes -XCPP

3

3 Answers

4
votes

Yes, you can use the .ghci file. See section 2.9 in the GHC manual.

~/.ghci

:set -XTemplateHaskell -XQuasiQuotes -XCPP

1
votes

cabal-ghci was exactly what I wanted.

-1
votes

Specify the extensions in a pragma at the top of the source files:

{-# LANGUAGE TemplateHaskell, QuasiQuotes, CPP #-}

For ghc options that are not within the scope of the language pragma, you can also use the OPTIONS_GHC pragma (and you could write {-# OPTIONS_GHC -XTemplateHaskell -XQuasiQuotes -XCPP #-} (note the lack of commas), but the language pragma is preferred where possible, as it is portable to other compilers that support the extensions).