Installing, Using, and Editing Haskell for CSE P505
Autumn 2016
Introduction
By the end of this, you should have:
- An editor with support for writing Haskell programs
- A Haskell compiler and interactive top-level
- Instructions on how to run the code you write
Installation
Here are several viable choices for getting a compiler and related
tools installed:
- Department Linux machines: If you are willing to connect to
a UW CSE Linux server named attu via ssh and run your code there, then
you do not need to install any tools yourself. Haskell is already
installed in /usr/bin (so the REPL is /usr/bin/ghci and the compiler
is
/usr/bin/ghc). Relevant
instructions for PMP students are provided by the department;
BS/MS students are surely already familiar with attu.
- Locally The
most current general
installation instructions give reasonable options for every major
operating system, but keep reading for our opinions and experience on
some of these:
- Windows: Either minimal or full installation options found on the
installation page should work. Download + double-click should “just work”.
- OS X: People have successfully installed and used Haskell via
MacPorts or Homebrew.
- Linux: Most likely your usual package manager will
leave you satisfied.
Running Haskell
- ghc: The Haskell compiler
- ghci: The read/eval/print loop for Haskell
In general, you can use ghci to experiment on the fly, and ghc to
compile an entire file at once. For the purposes of this class, you can
simply use the Makefile or simply run "ghc sourceFile.hs" to compile sourceFile.hs.
The complete manual for ghci can be
found here. Some highlights:
- To load source code into ghci for experimentation “:load thefile.hs”. Afterwards you should be able to use any functions defined in thefile.
- To exit ghci's read-eval-print loop, enter “:exit”
at the prompt.
On Windows, Dan usually uses the cygwin bash shell. If you do so,
you'll see a warning that for Ctrl-C to work, you should use ghcii.sh
instead of ghci. That is, uh, good advice.
Editing Haskell Files
As usual, you probably will want to use an editor with support for
indentation, syntax highlighting, etc. Because we are writing short
programs for homework purposes, we do not need lots of modern
features (e.g., auto-completion), but that may be a matter of taste.
It appears the most widely supported editor platform for Haskell is Emacs (which
does have Windows installation options). The Haskell IDE page lists other alternatives; we have heard that Sublime Text (which supports Windows) has particularly good support for Haskell. Atom (by Github) is another cross-platform editor with a Haskell module.
That said, the only solution known to work by Dan and John is to use haskell-mode with Emacs.
So... steps for using Emacs to edit Haskell files:
- Install Emacs. If you want known-to-work instructions for your
operating system, let us know and we will get them posted.
You will want Version 24.3 or higher for Haskell-mode to work.
- At least on Windows, we have not had good experience with getting
the Haskell mode added via Emacs' package manager.
So we don't recommend that, but doing it more manually is pretty easy,
so keep reading.
- Download or clone the github project https://github.com/haskell/haskell-mode. Extract or clone the directory wherever you want.
- In Emacs, open (or if you don't have one, create) the file
(Control-x Control-f) ~/.emacs and add to it the lines:
(add-to-list 'load-path "path-to-directory-containing-haskell-mode/haskell-mode/")
(add-to-list 'Info-default-directory-list "path-to-directory-containing-haskell-mode/haskell-mode/")
(require 'haskell-mode)
- Restart Emacs.
- Opening any file with a .hs should now use haskell-mode mode and you should be all set.