You are here

Haskell

Printer-friendly versionPrinter-friendly version
This document is under construction and pending finalising of the 2018 teaching software requirements. For more precise information please contact support.

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 SL7 distribution, but others are available using various commands. Here's a summary of installed versions:

DICE SL7
Version Command Location Notes
7.10.3 ghc /usr/bin/; /usr/lib Default version, Part of the 2012 Haskell Platform
8.4.3 module add ghc somewhere under /opt/ Must be enabled via module; libraries vary.

Optional GHC versions

These can be installed using the module system. To list available versions:

$ module show ghc

You'll note there can be multiple instances of the same version, due to the way some of our Haskell software is packaged. You can choose the default (usually latest) with a simple

$ module add ghc

or pick a specific version and library set with the full version string:

$ module add ghc/8.4.3+pandoc

In either case you may remove the currently activated version with:

$ module rm ghc

You may add this command to your .brc to override the default version for all of your future shells, or else enable and disable freely using the add/rm commands.

Installing Haskell libraries

Using Stack

The simplest way to install a custom version of Haskell 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.

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

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>

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.

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

cabal-install

The haskell interpreter/compiler installed above doesn't come with all of the packages in haskell-platform, so a good way to manage packages is with cabal-install.

First you need to find the version of the Cabal library that has been shipped with your binary copy of ghc

$  ghc-pkg list|grep Cabal
    Cabal-1.18.1.3
$

You then need to pull down, build and install a matching version of cabal-install. Normally this will be the latest version but if you have issues choose the version of cabal-install closest to the version of the Cabal library you have installed.

First download the source tarball and untar it

$ wget http://www.haskell.org/cabal/release/cabal-install-1.20.0.3/cabal-install-1.20.0.3.tar.gz
--2014-08-18 12:18:01--  http://www.haskell.org/cabal/release/cabal-install-1.20.0.3/cabal-install-1.20.0.3.tar.gz
Resolving www.haskell.org... 88.198.224.243
Connecting to www.haskell.org|88.198.224.243|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 274779 (268K) [application/x-gzip]
Saving to: `cabal-install-1.20.0.3.tar.gz'

100%[======================================>] 274,779     1.42M/s   in 0.2s    

2014-08-18 12:18:02 (1.42 MB/s) - `cabal-install-1.20.0.3.tar.gz' saved [274779/274779]

$ tar zxf cabal-install-1.20.0.3.tar.gz 

cd into the resulting directory and using an editor edit the bootstrap.sh file. Change the DEFAULT_PREFIX path to match where you have installed ghc:

...
do
  case "${arg}" in
    "--user")
      SCOPE_OF_INSTALLATION=${arg}
      shift;;
    "--global")
      SCOPE_OF_INSTALLATION=${arg}
      DEFAULT_PREFIX="/disk/scratch/ghc-latest"
      shift;;
    "--no-doc")
      NO_DOCUMENTATION=1
      shift;;
...

then build cabal by running

$ ./bootstrap.sh --global

This will download and build any package dependencies that are required and may take some time. At the end of the process you should have a cabal binary installed alongside the ghc and ghci binaries you've already installed.

Finally edit ~/.cabal/config and change the -- prefix line in the install-dirs global section to point at where you've installed ghc:

install-dirs global
  -- prefix: /disk/scratch/ghc-latest
  -- bindir: $prefix/bin
  -- libdir: $prefix/lib
  -- libsubdir: $pkgid/$compiler
  -- libexecdir: $prefix/libexec

you should now be able to install ghc packages for global use via cabal.

Last reviewed: 
15/08/2018

System Status

Home dirs (AFS)
Network
Mail
Other services
Scheduled downtime

Choose a topic