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 and Stack
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 and latest 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.
Step 2: Install VSCode
I won't bother repeating VSCode installation instructions here, just follow the instructions on the website. What I will do here is explain why we chose VSCode and why we definitely need you to use it if you're taking 5520.
I am usually an Emacs user, so it pains me a bit to recommend something else. That said, the goal here is both usability and consistency, and VSCode is shockingly good on both of those fronts. In addition, we plan to make use of VSCode's Live Share feature in class, which will allow students to work together on code similar to how they might collaborate on Google Docs. We think this feature alone is reason enough to strongly recommend VSCode for the class.
Step 3: Install Some Extensions
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.
- Haskell - The Haskell LSP client (installs the server automatically).
- haskell-linter - HLint is a tool that "lints" your code with suggestions of how to make it better. This extension runs HLint as you make changes.[^hlint]
You may need to install HLint, depending on how each project is set up. To do that, run
stack install hlint
to make sure HLint is available.
Then, you'll need to change a few configuration options. You could do this manually through the UI,
but I recommend hitting CTRL/CMD-SHIFT-P
to bring up the command palate, and hitting "Preferences:
Open Settings (JSON)". (Note: Do not try to edit the default settings---those are read only.) Then
you can just paste these settings in:
{
"editor.formatOnSave": true,
"haskell.hlint.logLevel": "warn",
"haskell.hlint.run": "onSave",
"haskell.formattingProvider": "ormolu",
"haskell.toolchain": {
"hls": "1.7.0.0",
"ghc": null,
"cabal": null,
"stack": null
},
"haskell.serverEnvironment": {
"PATH": "${HOME}/.ghcup/bin:$PATH"
},
// May be necessary
"haskell.hlint.executablePath": "<path-to-hlint>"
}
Moving Forward
At this point you should have a minimum 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 compiling the project using stack run
. 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!
Addendum: VSCode Live Share
Visual Studio Code has a feature called Live Share which enables collaborative editing in the style of Google Docs. It's an amazingly powerful tool, and we hope you will be able to make good use of it during CIS 5520. Here's how to get started:
- If you don't have the VSCode Live Share extension installed, make sure to install it.
- Choose one partner to "host". Both partners will be able to edit the code, but the host's version of the code is the one that will be modified.
- The host should go to the command palate (
CTRL/CMD-SHIFT-P
) and run "Live Share: Start Collaboration Session (Share)". If all goes well, the host should be notified that a link was copied to their clipboard. - The host can then share the appropriate link with their partner; once they click the link, the session will be underway.
A few important notes:
- During the setup process you might be asked to authenticate via GitHub. You should do this, using
the same GitHub account that you use for class.
- Live Share allows you to share terminals along with code. If you choose to do this
PLEASE USE A READ ONLY TERMINAL. VSCode does not put safety measures in place to prevent
damage to your system, and we are not responsible if things go wrong.
- You should still regularly commit your code to git
while live sharing. Git isn't just for
sharing code, it is also extremely helpful for versioning (and making sure you don't lose your
progress if your machine crashses).
- Make sure you're using Microsoft's version of VSCode (from the website). If you followed the
instructions above, you shouldn't have any issues.
- If you are on Linux, make sure you have gnome-keyring
installed.
Software versions for Fall 2022
For Fall 2022, 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.
-
i.e. this means that we are using GHC 9.0.2 with libraries base-4.15.1.0, containers-0.6.4.1, quickcheck-2.14.2, HUnit-1.6.2, filepath-1.4.2.1, mtl-2.2.2, pretty-1.1.3.6, network-3.1.2.7, directory-1.3.6.2, random-1.2.1.1
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. -
If you are running an older version of stack, you can upgrade with
stack upgrade
in the terminal. -
I've set up my VS Code to auto update and keep up with the latest version.
-
This VS Code extension is based on haskell-language-server 1.7.0.0
-
If you have an older version, check that
~/.stack/global-project/stack.yaml
useslts-19.19
and thenstack install hlint
. -
If you have an older version, check
~/.stack/global-project/stack.yaml
useslts-19.19
and thenstack install ormolu
.