As a student of CIS 552 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 1: Install 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. You can read the full instructions for installing Stack here, but on macOS and Linux you can just run
curl -sSL https://get.haskellstack.org/ | sh
As of writing, the current version of is Stack 2.3.1, although any recent version will likely be fine.
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 552.
I am usually an Emacs user (with VIM keybindings), 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",
// 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 file Basics.hs
in the editor. Open a new terminal (Terminal > New Terminal) to get a command line. Try starting ghci in the terminal and loading the module as described in the lecture notes.
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 552. 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.