Haskell logo CIS 5520: Advanced Programming

Fall 2024

  • Home
  • Schedule
  • Homework
  • Resources
  • Software
  • Style guide

Software

As a student of CIS 5520 you should try to have a working Haskell development setup as early as possible. While it is possible to write Haskell code in almost any editor or IDE, we highly recommend you use the tools that we outline here---doing so will make sure that we can help diagnose issues if anything goes wrong.

Step 0: Create a github account and install git

We have a separate page of instructions about how to install git and register with github. All lecture code and homework assignents will be distributed through public and private github repositories. VS Code supports git natively so you won't need to install any extensions to be able to directly work repositories within your IDE.

Step 1: Install GHCUP, Stack and hls

The Ghcup tool is an installer for the Haskell ecosystem. Follow the instruction on the homepage to download and install this tool.

Once it is working, you should use it to install the recommended version of Stack. Stack helps to achieve reproducible builds in Haskell projects by managing different versions of GHC (the de-facto standard Haskell compiler) and any external packages that are needed to build your code.

      ghcup install stack 2.15.5

You'll also want to use ghcup to install hls, the Haskell language server, which provides useful information to IDEs about Haskell code. We'll use the latest available version.

      ghcup install hls 2.9.0.1

Step 2: Install Haskell development tools: doctest, hlint and ormolu

Once stack has been installed you can use it to install other tools via the commandline.

stack install doctest-0.22.6
stack install hlint-3.6.1
stack install ormolu-0.7.2.0

The doctest tool allows you to run embedded documentation tests from the commandline. That way you'll be able to check that all of the test cases in your assignment pass.

The hlint tool provides you with insights about how you might refactor your Haskell code to make it more "Haskelly". It can be a bit overwhelming at first, as it will suggest changes that require importing new definitions, or enabling new language features, and is sometimes outside the scope of this class. But it is also a good source for learning about the language: how can you write code in a different way yet achieve the same result?

The VSCode development environment (see below) will find hlint if you have installed and give you suggestions as you type. These suggestions will be in a different color from the usual errors and warnings (make sure that you can tell the difference). Many hints will also come with code actions so that VSCode can automatically apply them.

The ormolu tool is a formatter for Haskell code, and will adjust your spacing, alphabetize your imports, and perform other changes that will make your code "prettier".

Code formatting is available in VS Code with the following shortcuts:

Windows: Shift + Alt + F
Mac: Shift + Option + F
Linux: Ctrl + Shift + I

While useful, both hlint and ormolu are optional for Haskell development. If you have trouble installing them, you can skip this step.

Note: if you end up with the wrong version of hlint or ormulu installed, you can update ~/.stack/global-project/stack.yaml to read resolver: lts-22.32 and then try stack install hlint again.

Step 3: Install VSCode and the Haskell Extension

I won't repeat the VSCode installation instructions here, just follow the instructions on the website.

After you install VSCode you should go to the extensions and install the Haskell LSP client.

The Language Server Protocol (LSP) provides a uniform way for programming languages and code editors to interact. Each language implements a language server, each editor implements a client, and the result is a smooth editing experience across the board. The Haskell extension for VSCode installs and manages a language server for Haskell. It should find the hls executable that you installed above, but if it does not, it will download it for you.l

Moving Forward

At this point you should have a viable Haskell setup. Try forking the introductory lecture code from github to your local machine and opening this project with VSCode.

Open the folder 01-basics in the editory. Open a new terminal (Terminal > New Terminal) to get a command line. Try starting ghci using stack ghci.

Your own project

You can play around Haskell by running

stack new <project-name>

and then editing the files in app/ and src/. If you'd like to tweak your development environment more, feel free to dig through VSCode's settings and extensions. If you're like me, you'll want to install the Vim plugin ASAP and change the color scheme to something solarized. Just keep in mind that you should avoid any modifications that might make it difficult to use the Live Share feature.

Good luck!

Trouble shooting

  • If you have a mac and use homebrew, make sure that your path puts ghcup before brew. In other words, your path should list something like: /Users/sweirich/.ghcup/bin/ before your path to brew's executables.

Software versions for Fall 2024

For Fall 2024, we are working with the following versions of the tools. Newer versions are also likely to work. You probably don't need to know this information, but if something seems odd with your setup, check to see if your versions ours.

  • https://www.stackage.org/lts-22.32

    This includes GHC 9.6.6.

    For tools installed via stack install make sure that your ~/.stack/global-project/stack.yaml points to the appropriate lts. This should give you the appropriate versions of hlint, ormolu, etc.

  • ghcup (0.1.30.0)

  • stack (2.15.5)

    If you are running an older version of stack, you can upgrade with stack upgrade in the terminal.

  • VS Code (1.91.1)

    I've set up my VS Code to auto update and keep up with the latest version.

  • Haskell (v2.4.4)

    This VS Code extension is based on haskell-language-server 2.0.0.1

  • hlint (3.6.1)

    If you have an older version, check that ~/.stack/global-project/stack.yaml uses lts-22.32 and then stack install hlint.

  • ormolu (0.7.2.0)

    If you have an older version, check ~/.stack/global-project/stack.yaml uses lts-22.32 and then stack install ormolu.

Design adapted from Minimalistic Design | Powered by Pandoc and Hakyll