:lang haskell

A language that’s lazier than I am

1. Description

This module adds Haskell support, powered by LSP (haskell-language-server).

1.1. Module flags

+lsp
Enables LSP support for haskell-mode utilizing haskell-language-server. Requires :tools lsp.

2. Prerequisites

It is recommended to install the haskell tooling using ghcup. Only ghc is needed for basic functionality:

ghcup install ghc

2.1. Cabal

To use Dante, you need cabal (the haskell package builder) and ghci (the compiler, syntax checker & repl):

2.1.1. MacOS

$ brew install cabal-install ghc

2.1.2. Arch Linux

$ pacman -S cabal-install ghc

2.1.3. openSUSE

$ zypper install cabal-install ghc

but +lsp users should also install the language server:

$ ghcup install hls

Installing cabal or stack as well is recommended, and can be done through ghcup.

haskell-mode provides support for hoogle, which can be installed through system package manager, cabal, or stack.

2.2. Haskell packages

You’ll need to install the following packages using stack or cabal:

  • (Dante users) ghc-mod

    $ stack install ghc-mod
    # or
    $ cabal install ghc-mod
    
  • hoogle

    $ cabal update
    $ cabal install happy haskell-src-exts   # ghc-mod/hoogle dependencies
    $ cabal ghc-mod hoogle
    # or
    $ stack install ghc-mod
    $ stack install hoogle
    

And ensure the binaries for these packages are in your PATH, e.g.

# place this in your profile file, like ~/.bash_profile or ~/.zshenv
export PATH="~/.local/bin:$PATH"

3. TODO Usage

This module has no usage documentation yet. Write some?

This module integrates haskell packages into Doom by providing things such as REPL support, project root recognition, etc. It also provide the following keybindings:

Keybinding Description
<localleader> b Build the current cabal project
<localleader> c Visit the .cabal file of the current buffer
<localleader> h Toggle visibility of the form at point
<localleader> H hides all top level functions

4. Configuration

After installing your preferred formatter, make sure to set lsp-haskell-formatting-provider to it.

Make sure to configure the lsp to use your perfered formatter, e.g.:

;; ~/.doom.d/config.el
(after! lsp-haskell
  (setq lsp-haskell-formatting-provider "brittany"))

4.1. Using the new-style cabal REPL

haskell-mode will typically detect what REPL to run based on your project (e.g. stack, (old-style) cabal or ghc). If you want the new-style cabal REPL you must set haskell-process-type manually:

(setq haskell-process-type 'cabal-new-repl)

5. Troubleshooting

6. TODO Appendix

This module’s appendix is incomplete. Write more?

6.1. External resources

Here are a few resources I’ve found indispensable in my Haskell adventures: