You are here

Haskell

Supported Versions

There are usually several versions of the Haskell Compiler available on DICE, though usually only one version of the Haskell Platform. The default (as invoked by the ghc, etc.) will usually match the default provided by our upstream DICE distributions, but others are available using various commands. Here's a summary of installed versions:


Version Command Location Notes
DICE Ubuntu Jammy (most teaching machines)
8.8.x ghc /usr/bin/; /usr/lib Default ghc*, cabal, etc.; Part of the 2014 Haskell Platform
DICE Ubuntu Focal (some servers and desktops)
8.10.2 ghc /opt/ghc Default ghc*, cabal, etc.
8.8.x ghc /usr/bin/; /usr/lib Part of the 2014 Haskell Platform

Installing Haskell libraries

Using Cabal

If you don't need a fully partitioned GHC environment and are happy with the installed versions on DICE, cabal might be the simplest way to install the Haskell packages you require.

To install a package first update the local database with:

$ cabal update

You can list available packages with

$ cabal list

and install them with

$ cabal install <packagename>

You can also install specific libraries for use in one project, but have them installed in your personal cabal cache in your home directory:

$ cd <path/to/project>
$ cabal install --lib --package-env . <packagename>

If your requested package has unmet dependencies, cabal will automatically try to fill them by downloading and compiling if required. You can see which packages are currently installed with:

$ ghc-pkg list

By default stack installs packages to ~/.cabal and ~/.ghc in your home directory.

For more details see the cabal install page.

If something goes wrong with Cabal

The cabal update command is expensive, downloading about 800Mb to your home directory at a stroke.  If you see odd errors about package indexes or databases being unavailable, it's likely that they have become corrupted (perhaps due to running out of disk quota). Regardless of the cause, the fix is the same, and it's relatively simple.

You might want to keep a note of the contents of your old ~/.cabal/config files, and any per-project environment settings (files named .ghc.environment.<architecture>-<ghcversion>), as we're about to destroy them (if they're in your AFS home directory, remember can find these in the Yesterday directory).

 $ rm -r ~/.cabal ~/.ghc

Before you proceed, check you have approximately 1Gb free quota, and rebuild the cabal index:

 $ fs lq -hu   # to check approx. 1Gb free quota
 $ cabal update

Then, if you've created a local package list for a project:

 $ cd <path/to/your/project>
 $ mv .ghc.environment* .ghc.environment.old
 $ cabal install --lib --package-env . <packagename>

Moving the package cache

In the case where quota is desperately tight and you are content to restrict your work to a single machine, perhaps just temporarily, the cabal cache can be moved into group space, scratch disk or even /tmp, by editing ~/.cabal/config to set the "remote-repo-cache" variable:

 (on each machine where you need to run this code, noting the result is undefined if the files go away!)
 $ mkdir -p /disk/scratch/$USER/.cabal  (or /tmp/$USER.cabal)
 $ rm -r ~/.cabal/packages
 $ edit ~/.cabal/config:
    remote-repo-cache: /disk/scratch//.cabal/packages

Then, back to your project directory:

 $ cabal update
 $ cabal install --lib --package-env . 

Using Stack

The simplest way to install libraries which require a custom version of Haskell itself is by using the Haskell Tool Stack. This will download a full version of the GHC, of your choice:

$ stack setup <ghc version>

and can also be used to install packages much as cabal does (indeed, it uses the Cabal repositories behind the scenes):

$ stack install <package spec(s)>

Stack is an immensely powerful tool and full reading of stack --help, as well as the stack online documentation, is advised.

Stack can also quickly consume vast amounts of space - a simple one-package install can quickly run to multiple gigabytes, so it's worth checking you have sufficient home directory quota, or else installing to scratch space. If you choose scratch space, remember that this is not backed up.

By default stack installs packages to ~/.stack but can involve ~/.cabal and ~/.ghc.

Building from Source Manually

If the above doesn't suit for whatever reason, it's possible to install Haskell in a local directory (or /disk/scratch or /group/...) and configure the package management to use this in preference to the rpm install.

ghc

First download the appropriate binary for ghc, into a temporary directory, untar the tar file, cd into the directory this creates and then run ./configure pointing it at the directory you want to install ghc into:

$ tar jxvf ghc-7.8.3-x86_64-unknown-linux-centos65.tar.bz2 
$ cd ghc-7.8.3/
$ mkdir /disk/scratch/ghc-latest
$ ./configure --prefix /disk/scratch/ghc-latest/

This will set ghc up to install into a series of directories under /disk/scratch/ghc-latest but you can use any directory you have write permissions on. Then run

$ make install

to install the binaries. Finally add the <prefix>/bin directory to your PATH environmental variable by putting

export PATH=<prefix>/bin:$PATH

in your .brc file. For example:

export PATH=/disk/scratch/ghc-latest/bin:$PATH
Last reviewed: 
01/02/2024

System Status

Home dirs (AFS)
Network
Mail
Other services
University services
Scheduled downtime

Choose a topic