Emacs for Haskell

Haskellers are not exactly blessed with an abundance of IDEs. After trying Vim, Atom and Haskell for Mac I converged on Emacs with the Intero package. First let's run through a selection of alternatives that all have great features but are each lacking in some particular way. Haskell for Mac

Haskellers are not exactly blessed with an abundance of IDEs. After trying Vim, Atom and Haskell for Mac I converged on Emacs with the Intero package. First let's run through a selection of alternatives that all have great features but are each lacking in some particular way.

Haskell for Mac

Haskell for Mac was nice while I was learning Haskell basics, but it's not adequate for larger projects because the .cabal file inside the project folder can't be edited and it doesn't allow for multiple executables, or any custom project structure. On the upside, no other tool I've seen integrates the REPL as nicely as Haskell for Mac does. For beginners, this is a very good choice.

Vim

I struggled to configure Vim until I discovered Haskell-Vim-Now, which promises that "in less than ten minutes your Vim will transform into a beautiful Haskell paradise". I had some problems with the installation but these were resolved quickly thanks to very dedicated maintainers.
(See Issue #199 of Haskell-Vim-Now and Issue #63 of the Haskell codex package)

My remaining grief with Vim is the speed of type lookups and linter runs (Issue #201).

Atom

In general I really like Atom, and after some fiddling with path settings, it worked very well. What I don't like about Atom for Haskell is that the REPL isn't that well integrated, yet. The IDE-Haskell REPL package is in beta and currently offers a rather minimal interface into ghci.
Atom

Emacs

A hassle-free, complete, one-stop solution is Intero for Emacs, and this is what is described here. It's really straightforward and does all the things you'd want, such as:

  • syntax highlighting etc.
  • ghci backend
  • type checking
  • type identification
  • auto-complete
  • Haskell stack based

Install theme

First, lets' pick a theme. Here's a reminder of how to do that in Emacs:

M-x package-install <RET> theme-name  

for theme-name plug in any theme available in MELPA, such as dracula or atom-dark (see below). Then make a theme the default with this line in .emacs:

(load-theme 'theme-name t)

The default font size is set as follows:

(set-face-attribute 'default nil :height 140)

where the value is 1/10pt. (See Q on stackexchange.)

Nice themes

Fonts

A nice list of monospace fonts for programming is at narga.net.

To set the font use this:

(set-default-font "Inconsolata 12")

This Q on stackexchange has more info.

Intero for emacs

Intero is a complete interactive development program for Haskell

Follow the instructions here: http://commercialhaskell.github.io/intero/.

Default key bindings:

Key bindingDescription
M-. Jump to definition
C-c C-i Show information of identifier at point
C-c C-t Show the type of thing at point, or the selection
C-u C-c C-t Insert a type signature for the thing at point
C-c C-l Load this module in the REPL
C-c C-r Apply suggestions from GHC
C-c C-k Clear REPL
C-c C-z Switch to and from the REPL

Why does C-c C-l start the session, not the process?

Don't use emacs' haskell-session-, instead use haskell-process-:

CommandDescription
haskell-process-cabalPrompts for a Cabal command to run
haskell-process-cabal-buildBuild the Cabal project
haskell-process-cdChange directory
haskell-process-restartRestart the inferior Haskell process
haskell-process-clearClear the current process
haskell-process-reloadReload the current buffer file
haskell-process-load-fileLoad the current buffer file

Here's how this looks in action: Emacs

Helm

Helm is an incremental completion and selection narrowing framework for Emacs.

Right now I only have this in my init.el:

(require 'helm-config)
(helm-mode 1)

What I get is a nicer C-x b for switching between buffers.

Other packages

hindent

stack install hindent  

and add this to the init.el:

(add-hook 'haskell-mode-hook #'hindent-mode)

Install hindent emacs package.
Then, by calling M-q, you can reformat the current declaration.

Fails

flymake-haskell-multi

https://github.com/purcell/flymake-haskell-multi: no success.

company GHC

https://github.com/iquiw/company-ghc: no success

Tips

manage emacs packages

actiondescription
M-x package-list-packageslist available packages
M-x package-refresh-contentsrefresh list of packages

find init.el file:

M-: <RET> (find-file user-init-file)

The "right" Emacs for Mac Os X

See this Q on stackexchange for a review of the different Emacs versions on Mac OS X, and how to best compile Emacs using Homebrew on Mac:

brew install emacs --HEAD --use-git-head --with-cocoa --with-gnutls \  
    --with-rsvg --with-imagemagick