Getting Started with Cabal

Cabal is the Haskell package and build tool.

The following are a few of the “getting started” commands.

What version do you have of Cabal?

Run the following

cabal --version

Check for updates to Cabal

You can check

cabal new-install Cabal cabal-install

Check for package updates

This command will pull the latest package list from hackage.haskell.org

cabal update

Creating a new project

We can create a new Haskell project using

cabal init

This will create a Main.hs, Setup.hs and a .cabal file for your configurations. We can then edit the .cabal file or we can run the interactive version and supply details using

cabal init -i

Building our project

We can build our project by simply using

cabal build

Running our project

To run (or build and run)

cabal run

Cleaning our project

cabal clean

Running the ghci repl

You can run ghci by simply typing

ghci

Or you can run the ghci that’s available via cabal using

cabal repl

Adding a library

We can download and install package from The Haskell Package Repository using the command

cabal install --lib QuickCheck HUnit

This installs the packages QuickCheck and HUnit from the package repository. The –lib is used for packages which do not contain an executable (i.e. a library package). We can also install .gz packages by specifying a file location or URL.

Packages are then stored on Windows in

%USERPROFILE%\AppData\Roaming\cabal\store\ghc-8.10.1

References

Welcome to the Cabal User Guide