Haskell - ArchWiki

# Haskell

Haskell is a general purpose, purely functional, programming language.

## Installation

Haskell generates machine code that can be run natively on Linux. There is nothing special required to run a binary (already compiled) software, like the ones provided in the official repositories or by the ArchHaskell group. On the other side, AUR packages or source codes requires a compiler to build the software.

Installing the compiler alone permits to build Haskell source code. A few additional tools are needed for development work.

### Compiler

To build a Haskell source–code into native–code, a compiler must be installed. There are several implementations available, but the one used most (which is now de facto the reference) is the GHC (Glasgow Haskell Compiler). It is available in the official repositories as ghc.

You can try it with the following file:

    Main.hs

    main = putStrLn "Hello, World"

and by running:

    $ ghc Main.hs
    $ ./Main

    Hello, World

### Haskell development tools

To start developing in Haskell easily, one option is the haskell-platform bundle which is described as:

  The easiest way to get started with programming Haskell. It comes with all you need to get up and running. Think of it as "Haskell: batteries included".

Although an AUR package exists (haskell-platformAUR[broken link: archived in aur-mirror]), the Haskell Platform can be advantageously replaced by installing the following packages from the official repositories:

- ghc (ghc) — The compiler
- cabal-install (cabal-install) — A command line interface for Cabal and Hackage
- haddock (haskell-haddock-api and haskell-haddock-library) — Tools for generating documentation
- happy (happy) — Parser generator
- alex (alex) — Lexical analyzer generator

Alternatively, you can use stack to manage your Haskell environment by following the Arch Linux install instructions.

## Managing Haskell packages

This article or section needs expansion.

Reason: There's also stackage (Discuss in Talk:Haskell#)

Many Haskell libraries and executables are grouped in packages. They are all available on Hackage. To install and manage these packages, several methods are available and unusual ones are explained in the rest of this section.

The recommended workflow is the following:

- Official repositories or ArchHaskell repository as principal source of Haskell packages (the or is exclusive here)
- cabal-install (possibly with sandboxes) for Haskell development
- Arch User Repository for packages that are not available elsewhere

cblrepo is a tool used for maintaining Haskell packages for Linux distributions. A wrapper around this, cabal2pkgbuild-gitAUR[broken link: archived in aur-mirror], can create PKGBUILD files from Hackage packages. See Haskell package guidelines for more information on creating new Haskell packages.

### Pros/Cons of the different methods

The following table documents the advantages and disadvantages of different package management styles.

Method | Pros | Cons
--- | --- | ---
Official repositories | Provided by ArchLinux developers, consistent versions of packages, already compiled | Only a few packages available
ArchHaskell repository | Provided by ArchHaskell group, consistent versions of packages, already compiled | Need manual intervention to get started with
cabal-install | All packages available | Installed in home folder, cabal-install is not a package manager, incompatible versions of packages possible (aka. cabal hell)
Arch User Repository | Simple to get started | Risk of unmaintained or orphaned packages, incompatible versions of packages possible

### ArchHaskell repository

See ArchHaskell for details.

### cabal-install

Warning: Discouraged method, keep in mind that cabal-install is not a package manager.
Note: The only exception is for Haskell development, where cabal-install is the recommended tool. Since version 1.18, cabal provides a sandbox system that permits to isolate different versions of libraries for different projects. There is an introduction to cabal sandbox here.

#### Preparation and $PATH

Install cabal-install from the official repositories.

To run installed executables without specifying the path, the cabal binary folder `~/.cabal/bin` must be added to the `$PATH` variable. That can be done by putting the following line in your shell configuration file, for instance `~/.bashrc` for bash or `~/.zshrc` for zsh:

    PATH=$PATH:~/.cabal/bin

To run executables within a cabal sandbox, you must also add

    PATH=$PATH:.cabal-sandbox/bin

#### Installing packages

    $ cabal update
    $ cabal install <pkg>

It is possible to install a package system–wide with the `--global` flag, but this is strongly discouraged. With the user–wide install, all files are kept in `~/.cabal` and libraries are registered to `~/.ghc`, offering the possibility to do a clean-up easily by simply removing these folders. With system–wide install, the files will be dispersed in the file system and difficult to manage.

#### Removing packages

There is no easy way to do it.

One thing to make your life easier is use zsh auto completion to find all the haskell packages.

## See also

- Learn You a Haskell for Great Good!
- Real World Haskell

Category:

- Programming languages

Hidden categories:

- Pages with broken package links
- Pages or sections flagged with Template:Expansion