Skip to content

Haskell Interactive Mode Setup

John Feltz edited this page Jul 19, 2015 · 8 revisions

The most straight-forward way to get setup with Interactive Mode is to bind the right keybindings and set some customizations. This page contains a good base setup.

To enable the minor mode which activates keybindings associated with interactive mode, use:

(require 'haskell-interactive-mode)
(require 'haskell-process)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)

Customizations

This enables some handy and benign features.

(custom-set-variables
  '(haskell-process-suggest-remove-import-lines t)
  '(haskell-process-auto-import-loaded-modules t)
  '(haskell-process-log t))

Bindings

Haskell-mode bindings

This gives the basic ways to start a session. In a Haskell buffer:

  • Run C-` to make a REPL open, this will create a session, start GHCi, and open the REPL.
  • Or: run C-c C-l to load the file. This will first try to start a session as the previous command does.
  • Or: run any command which requires a running session. It will always prompt to create one if there isn't one already for the current project.
(define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
(define-key haskell-mode-map (kbd "C-`") 'haskell-interactive-bring)
(define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
(define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
(define-key haskell-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
(define-key haskell-mode-map (kbd "C-c c") 'haskell-process-cabal)
(define-key haskell-mode-map (kbd "SPC") 'haskell-mode-contextual-space)

Cabal-mode bindings

The below commands pretty much match the ones above, but are handy to have in cabal-mode, too:

(define-key haskell-cabal-mode-map (kbd "C-`") 'haskell-interactive-bring)
(define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
(define-key haskell-cabal-mode-map (kbd "C-c c") 'haskell-process-cabal)

GHCi process type

Important: You will want to choose the kind of GHCi process you want. By default it is ghci. There is a variety now:

  • ghci
  • cabal-repl
  • cabal-dev
  • cabal-ghci

If you are unsure, you can use ghci. If you're using a more modern Cabal, you can use cabal-repl, which will launch cabal repl to run the GHCi process. This is a handy way to get all your settings properly setup in your GHCi.

Customize this setting by running M-x customize-variable haskell-process-type RET, or by setting the code:

(custom-set-variables
  '(haskell-process-type 'cabal-repl))

Troubleshooting

Launching your GHCi process can fail when you're first getting setup, depending on the type you choose. If it does fail to launch, switch to the buffer *haskell-process-log* and see what's up. The buffer contains a log of incoming/outgoing messages to the GHCi process.

See also troubleshooting the REPL.

See also architecture.

All done!

You're all done and ready to go! But wait!

There're a bunch more features to this mode and for which you might want to add configurations and keybindings. So it is suggested that once you've setup and played with the above, you continue reading what other features are available in the Haskell Interactive Mode documentation.