Starting with a right development environment can save you from a lot of future headaches. So here is a short write up on how to quickly setup your own haskell development environment.
Stack is a cross platform build tool. It can be used for setting up your project, installing compiler and dependencies, building and deploying the generated binary. It You can follow the instructions on this page to install stack.
To setup a new project with stack you can run
stack new command.
stack new <project-name>
Once the setup is done, you can
cd to your project and build it
cd <project-name> stack build
Stack gives you a
file-watch option which watches for file changes in your project and build the project automatically after every file change.
stack build --file-watch
If you look at the end of the output from the
build command, you’ll find the path where stack saved the executable after build.
stack provides you with an
exec option to run that binary without typing the whole executable path.
stack exec <your-project-exe>
There are a lot more features which are given by the stack. You can read more about it in the stack doc.
Setting up an IDE
There is a lack of good out of the box IDE in the haskell world. If you are brave enough, you can get on your haskell journey with a plain text editor but having IDE like features are always a nice to have.
Though there is no one stop solution for it, there have been a lot of plugins like hlint, stylish-haskell, ghc-mod, haskell-ide-engine which one can integrate with their favorite text editor.
- Emacs with intero and haskell-mode
- Vim with ale, hie
- VSCode with Haskero or hie
- Atom and ide-haskell
You can use stack to access documentation of packages locally
stack haddock --open text
If you are a fan of something like a
make file, you can use shake to write a build system for your project.
Haskell gives you a nice repl environment with
ghci. You can fire up a
ghci session using
You can interactively run functions, evaluate expressions, find their types, test your code etc in it. If you want to know more, read about it here.
You can even add dynamic breakpoints in your code using ghci. More on it in haskell wiki.
ghci can also be used to setup a fast incremental development setup using
ghci behind the scenes to build the code and can be set to reload on file change. You can also run a command after each build using the
--test flag. Read this beautiful blog-post by Matt Parsons to know more about it.