#Haskell, Stack and Intellij IDEA IDE setup tutorial how to get started Upon completion you will have a sane, productive Haskell environment adhering to best practices.
- Haskell is a programming language.
- Stack is tool for Haskell projects. (similar tools for other languages include Maven, Gradle, npm, RubyGems etc)
- Intellij IDEA IDE is a popular IDE.
Don't install Haskell, Stack, Cabal or any other Haskell tool or library using your OS package manager or using Cabal.
Instead, download Stack from http://docs.haskellstack.org/en/stable/install_and_upgrade/#linux and extract it into ~/.local/bin (ie the complete path to stack should be ~/.local/bin/stack) and add ~/.local/bin to $PATH. (adding a folder to $PATH is beyond the scope of this tutorial, search and you will find)
Go to the folder where you want to create your Haskell project and run
stack new my-project
cd my-project
stack setup
stack build
stack exec my-project-exeStack installs Haskell (ghc) to ~/.stack/programs/x86_64-linux/ghc-7.10.3/bin/ghc, project-specific dependencies to appropriate locations inside the project, and builds and runs the project.
- Make sure you're not inside a Haskell project folder and run
stack install hlint stylish-haskell ghc-modto install tools required by the IDE plugin for Haskell. (they will be installed to ~/.local/bin)
- Download and Intellij IDEA IDE from http://www.jetbrains.com/idea and extract it to some appropriate folder.
- Start IntelliJ up and install the plugin
Intellij-Haskell. (NOTE there are a number of different mutually exclusive Haskell plugins- they can't be installed simultaneously. If other Haskell plugins are already installed, uninstall them before installing theIntellij-Haskellplugin) - Restart IntelliJ.
Settings|Other|Haskell| add the respective paths to the tools (eg forghc-mod~/.local/bin/ghc-mod)File|New|Project| selectHaskell moduleand tick the Haskell box |Next| create GHC SDK using path to GHC binaries~/.stack/programs/x86_64-linux/ghc-7.10.3/bin|Project name:my-project,Project location:path to root of my-projectTools|Add Haskell package dependencies. This is what enables viewing docs while coding. It creates a folderideaHaskellLibin which it runsstack unpackfor every dependency output bystack list-dependencies. Remember to repeat this step on any change in dependencies. Add theideaHaskellLibfolder to the.gitignorefile for the project (it's not part of your projects source code).Project Structure|Modules| markideaHaskellLib,appandsrcasSources,testasTests.
Most or all of the usual features of Intellij like auto-completion, go to declaration ctrl+b etc should now work.
Terminal has to be used for this. (if the IntelliJ terminal can't find stack, add ~/.local/bin to $PATH in .bashrc and create a new Intellij terminal instance)
stack build && stack exec my-project-exeOne of the advantages of Haskell is the interactive interpreter. Go to path to root of my-project and run
stack ghcito fire up the interpreter, then
:load Main
mainto interactively load the Main module and call the main function. New functions can also be defined and tried out interactively. It's a faster development flow than writing the source code in the source code files and building and running the project all the time.
Stack can install and manage multiple Haskell versions, and different versions of different libraries in different projects. Stack itself can be updated simply by running
stack updateThis is why neither Haskell, Stack, Cabal nor any other Haskell tool or library should be installed and managed through the OS package manager or Cabal. (anything installed and managed through the OS package manager will be a single, global version, and the versions are often lagging severely)
As previously seen, there are other IntelliJ plugins for Haskell that may or may not be better than, have more features etc than the Intellij-Haskell plugin, but I've been unable to get any of them running. Which brings us to...
I tried several times to pick up Haskell, but always gave up, not due to anything to do with the language itself, but due to not being able to set up a sane, productive environment. After lots of time, energy and frustration it appears as if I've finally figured out how to do it. This Gist is for my own future reference, but I hope others will find it useful as well, and that others won't have to go through what I went through just in order to get started.


FYI, I have released new version of IntelliJ Haskell plugin which mainly depends on Stack and Intero.