CSE 341 - Programming Languages - Autumn 2008

Running Haskell

We're using the Glasgow Haskell Compiler in 341 this quarter. (This is the de facto standard version.)

On the CSE Undergrad Windows Machines

Start Haskell via the "Start" menu. It's here:
Programs / DEV TOOLS & LANGUAGES / GHC (Haskell) / 6.8.3 / GHCI

(The "I" in "GHCI" stands for "interactive", as opposed to just compiling something.)

There are also local copies of documentation under
Programs / DEV TOOLS & LANGUAGES / GHC (Haskell) / 6.8.3

A few essential commands:

If you just want to try Haskell without loading any files, just start it up. For anything interesting, though, you'll want to have a file with defintions in it. A simple way to do this is to use your favorite editor to create a file (with the extension .hs) in your home directory or a subdirectory. Save the file but leave the editor open on it. Then start up Haskell, use the :cd command to change to your home directory or subdirectory, then the :load command to load the file. Try things out. If you want to edit your file, do so and save it, and then back in Haskell reload the file using :reload.

The above directions may be all you want for 341; and in any case I'd suggest starting out that way. For students comfortable with emacs (or who are willing to learn) running Haskell from emacs is more convenient in the long run. There are directions for installing and running this at Haskell mode for Emacs.

On attu or other CSE undergrad linux machines

We've asked CSE Support to install Haskell on the undergrad linux machines but this hasn't been done yet. In the meantime I installed it in a courses directory where you can run it:
/cse/courses/cse341/haskell/bin/ghci
To use this conveniently, add /cse/courses/cse341/haskell/bin/ to your search path. The exact syntax depends on what shell you are using. If you are using cshrc, add this line to your .cshrc file in your home directory:
set path = ($path /cse/courses/cse341/haskell/bin)
If you are using bash, add this to your .bashrc file:
export PATH=$PATH:/cse/courses/cse341/haskell/bin/

The next time you log in, you should be able to start up Haskell from the command line. Just type ghci to start it, or ghic myfile.hs to start it and load myfile.hs.

On a Personal Machine

Haskell is available for Windows, Mac, Linux -- see the download page at http://haskell.org/ghc/download_ghc_683.html.

Install it and follow the directions above to run it. One additional thing you can do on a personal Windows machine (as well as Mac or Linux) is start up Haskell from the command line. Just type ghci to start it, or ghic myfile.hs to start it and load myfile.hs. (This doesn't work on the CSE Lab windows machines because ghci isn't on the search path -- if this annoys you and you know how to edit environment variables on windows, go ahead and add its directory to your path.)

Beware the Evil Tab!

Unlike the situation in most programming languages, whitespace is significant in Haskell. So that you can see whether things are linking up properly use a fix-pitch font when editing. Haskell has some rule about how tabs are processed, but I strongly suggest that you avoid tabs in Haskell code and always use spaces instead.

For emacs, if you use the Haskell mode for Emacs, it will avoid using tabs in files. Otherwise, by default, Emacs inserts tabs in place of multiple spaces when it formats a region. Putting the following in your .emacs file turns this off:

     (setq-default indent-tabs-mode nil)