2019-04-07 16:46:59 -04:00
#+TITLE : lang/haskell
#+DATE : January 16, 2017
#+SINCE : v0.7
#+STARTUP : inlineimages
2017-05-25 20:08:50 +02:00
2019-04-07 16:46:59 -04:00
* Table of Contents :TOC:
- [[#description ][Description ]]
- [[#external-resources ][External resources ]]
- [[#module-flags ][Module Flags ]]
- [[#plugins ][Plugins ]]
- [[#prerequisites ][Prerequisites ]]
- [[#cabal ][Cabal ]]
2020-09-24 23:15:37 +08:00
- [[#lsp-haskell-language-server ][LSP (haskell-language-server) ]]
2020-03-29 18:28:20 -04:00
- [[#lsp-ghcide ][LSP (ghcide) ]]
2019-12-01 05:13:10 -05:00
- [[#stack ][Stack ]]
2019-04-07 16:46:59 -04:00
- [[#haskell-packages ][Haskell packages ]]
- [[#configuration ][Configuration ]]
- [[#using-the-new-style-cabal-repl ][Using the new-style cabal REPL ]]
- [[#troubleshooting ][Troubleshooting ]]
* Description
2020-04-14 19:27:33 -04:00
This module adds [[https://www.haskell.org/ ][Haskell ]] support, powered by either [[https://github.com/jyp/dante ][dante ]] (the default) or LSP
(haskell-language-server or ghcide).
2017-05-25 20:08:50 +02:00
+ Code completion (~company-ghc~ )
+ Look up documentation (~hoogle~ )
+ eldoc support (~dante~ )
+ REPL (~ghci~ )
+ Syntax-checking (~flycheck~ )
+ Code navigation (~dante~ )
2019-07-14 14:43:45 +02:00
+ [[https://github.com/hlissner/doom-snippets/tree/master/haskell-mode ][Snippets ]]
2017-05-25 20:08:50 +02:00
2019-04-07 16:46:59 -04:00
** External resources
2019-12-01 22:31:19 -05:00
Here are a few resources I've found indispensable in my Haskell adventures:
2017-10-18 17:55:04 +02:00
2019-04-07 16:46:59 -04:00
+ [[http://learnyouahaskell.com/ ][Learn you a haskell for great good ]]
+ [[http://haskellbook.com/ ][Haskell Programming from first principles ]]
+ [[https://github.com/krispo/awesome-haskell ][Awesome Haskell ]]: an extensive list of haskell resources
+ [[https://docs.haskellstack.org/en/stable/README/ ][The Haskell Tool Stack docs ]]
** Module Flags
+ =+dante= Enables dante; a fork of intero aimed at lightweightedness. It
doesn't depend on =stack= , supports both ~cabal~ -only and ~stack~ projects,
but lacks eldoc support.
2020-03-29 18:28:20 -04:00
+ =+ghcide= Enables LSP support with ghcide (requires the ~:tools lsp~ module).
2020-09-24 23:15:37 +08:00
+ =+lsp= Enables LSP support with haskell-language-server (requires the ~:tools lsp~
2020-03-29 18:28:20 -04:00
module).
2019-04-07 16:46:59 -04:00
** Plugins
+ [[https://github.com/haskell/haskell-mode ][haskell-mode ]]
+ =+dante=
+ [[https://github.com/jyp/dante ][dante ]]
+ [[https://github.com/jyp/attrap ][attrap ]]
+ =+lsp=
+ [[https://github.com/emacs-lsp/lsp-haskell ][lsp-haskell ]]
* Prerequisites
2020-04-14 19:27:33 -04:00
Depending on whether you use Dante, haskell-language-server or ghcide, your
dependencies will differ:
2019-04-07 16:46:59 -04:00
+ Dante users need =cabal= , =ghc= and =ghc-mod=
2020-09-24 23:15:37 +08:00
+ LSP users need the =haskell-language-server= LSP server OR =ghcide=
2019-04-07 16:46:59 -04:00
+ All users will need the =hoogle= package
** Cabal
To use Dante, you need =cabal= (the haskell package builder) and =ghci= (the
compiler, syntax checker & repl):
2017-05-25 20:08:50 +02:00
2019-04-07 16:46:59 -04:00
*** MacOS
2017-05-25 20:08:50 +02:00
#+BEGIN_SRC sh
2019-04-07 16:46:59 -04:00
brew install cabal-install ghc
2017-05-25 20:08:50 +02:00
#+END_SRC
2019-04-07 16:46:59 -04:00
*** Arch Linux
2017-05-25 20:08:50 +02:00
#+BEGIN_SRC sh
2019-04-07 16:46:59 -04:00
sudo pacman -S cabal-install ghc
2017-05-25 20:08:50 +02:00
#+END_SRC
2019-08-27 10:50:37 +02:00
*** openSUSE
#+BEGIN_SRC sh :dir /sudo::
sudo zypper install cabal-install ghc
#+END_SRC
2020-09-24 23:15:37 +08:00
** LSP (haskell-language-server)
2019-04-07 16:46:59 -04:00
You will need =stack= and =git= installed.
2017-10-18 17:55:04 +02:00
2020-09-24 23:15:37 +08:00
You will find a comprehensive [[https://github.com/haskell/haskell-language-server#installation ][instructions for haskell-language-server on its project page ]], but if you are using [[https://www.haskell.org/ghcup/ ][ghcup ]]:
2017-10-18 17:55:04 +02:00
2020-03-29 18:28:20 -04:00
#+BEGIN_SRC bash
2020-09-24 23:15:37 +08:00
ghcup install hls
2017-10-18 17:55:04 +02:00
#+END_SRC
2020-03-29 18:28:20 -04:00
** LSP (ghcide)
See https://github.com/digital-asset/ghcide for install instructions.
2017-10-18 17:55:04 +02:00
2019-12-01 05:13:10 -05:00
** Stack
2020-04-14 19:27:33 -04:00
To use LSP, you need =stack= :
2019-12-01 05:13:10 -05:00
*** MacOS
#+BEGIN_SRC sh
brew install haskell-stack
stack setup
#+END_SRC
*** Arch Linux
#+BEGIN_SRC sh
sudo pacman -S stack
# Replace pacaur with your AUR package manager of choice
pacaur -S ncurses5-compat-lib
stack setup
#+END_SRC
*** openSUSE
#+BEGIN_SRC sh :dir /sudo::
sudo zypper install stack
stack setup
#+END_SRC
2019-04-07 16:46:59 -04:00
** Haskell packages
You'll need to install the following packages using ~stack~ or ~cabal~ :
+ (Dante users) =ghc-mod=
#+BEGIN_SRC sh
stack install ghc-mod
# or
cabal install ghc-mod
#+END_SRC
+ =hoogle=
#+BEGIN_SRC sh
cabal update
cabal install happy haskell-src-exts # ghc-mod/hoogle dependencies
cabal ghc-mod hoogle
# or
stack install ghc-mod
stack install hoogle
#+END_SRC
And ensure the binaries for these packages are in your ~PATH~ , e.g.
2017-10-18 17:55:04 +02:00
#+BEGIN_SRC sh
2019-04-07 16:46:59 -04:00
# place this in your profile file, like ~/.bash_profile or ~/.zshenv
export PATH="~/.local/bin:$PATH"
2017-10-18 17:55:04 +02:00
#+END_SRC
2019-04-07 16:46:59 -04:00
* Configuration
** 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:
2017-05-25 20:08:50 +02:00
2019-04-07 16:46:59 -04:00
#+BEGIN_SRC emacs-lisp
(setq haskell-process-type 'cabal-new-repl)
#+END_SRC
2017-05-25 20:08:50 +02:00
2019-04-07 16:46:59 -04:00
* Troubleshooting
+ Stack users: a ~dist/setup-config~ file in your project may cause [[https://github.com/DanielG/ghc-mod/wiki#known-issues-related-to-stack][ghc-mod to
not work]].