Setting up a Haskell Environment

This document describes how to set up Haskell on your computer for use in my classes. There is a separate section for each platform, you can ignore sections for the platforms you aren't using. If you can suggest corrections or clarifications, of if you successfully set up Haskell on a platform not mentioned here, don't hesitate to send me a note. I would love to expand on the information here based on your experience.

This description is for modern Windows systems. However, the tool I recommend using ("Stack") is available for Linux and MacOS platforms as well. These instructions can likely be easily adapted to work on all supported systems.

  1. Download Stack. This is a package manager and build tool for Haskell programs. It allows you to easily download libraries and will even download and set up a Haskell compiler for you.

  2. Run the installer and accept the default locations. Using the default locations will make it easier for Stack to upgrade itself when (and if) you decided to do that. Be aware that the installer will create a folder named sr immediately off the root of the C: drive. This is the "Stack root" folder. The installer will set the STACK_ROOT environment variable to point at this folder; it is an essential folder. Stack will not work without it! The Rationale for the short path (C:\sr) is to work around a path length limitation in Windows. While you can, in theory, put this folder in other places, doing so is not recommended.

  3. Stack is a command line tool. Although graphical IDEs for Haskell exist, they tend to be either not maintained, platform limited, or missing desirable features. Thus I recommend sticking to a tool like Stack together with the text editor of your choice. Good editors include Notepad++, jEdit, Vim, and Emacs (the last two are from the Unix world, but are available on Windows). Install the editor poison of your choice.

  4. Open a fresh console window and type:

            > stack upgrade
            > stack setup

    The first command just verifies that you have the latest version of Stack. It should print a message saying this (or upgrade itself to the latest version if, for some reason, you don't have that version). The second command sets up Stack for use. This takes a little time as Stack will download and install the actual Haskell compiler (ghc) as well as initialize the package index.

    When the setup completes, close the console window and open a fresh one.

  5. Using a text editor open the file C:\sr\config.yaml and add information about yourself there. This file is used by Stack to provide some default project attributes. You can override these attributes on a project-by-project basis, but you should have appropriate defaults defined. Here is what my config.yaml looks like:

                author-name: Peter Chapin
                copyright: Peter Chapin
                github-username: pchapin

    You are now ready to use Stack for Haskell programming!

  6. You probably should test Stack to make sure that it works okay. Let's use one of Stack's project templates to create a skeletal project. Use a command such as:

            > stack new hello new-template

    This command creates a new project named hello (technically that's the name of a Haskell package you are creating) using the template new-template. The command will create a folder named hello holding the project. Change into that folder.

  7. You can now build the skeleton program using the command:

            > stack build

    The skeleton program consists of a library in Lib.hs and a main file in Main.hs. You can run the executable using:

            > stack exec hello-exe

    The output should be "someFunc."