Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are `ghc-pkg` and `cabal` programs related? (Haskell)

As I know cabal is a program to manage installation of packages like FreeBSD's pkg_add. But there is another tool called ghc-pkg. I don't know why there are two different programs. What's the role of each of them and how are they related?

like image 588
eonil Avatar asked Feb 28 '11 06:02

eonil


People also ask

What is GHC package?

This tool is perhaps most often used for uninstalling unneeded packages and those packages that are incompatible with packages that the user wants to install. It is also used for checking which packages are installed or have been broken by installs of other packages.

Where are Haskell packages installed?

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. By default stack installs packages to ~/. cabal and ~/. ghc in your home directory.

How to install cabal file?

To install the cabal executable you can use ghcup (if you're using Linux), the Haskell Platform, install the cabal-install package from your distributions package manager (if using Linux or Mac), or download the source or prebuilt binary from the Download page.


2 Answers

Cabal is a building and packaging library for Haskell, kind of "Haskell autotools". It reads .cabal files and Haskell packages usually have a file Setup.hs which uses Cabal to build the package. Then there's also cabal command provided by the cabal-install package. It provides commands for running Setup.hs script and some package management functions, like installing packages directly from Hackage. You should read this blogpost by Ivan Miljenovic which explains the role of Cabal, cabal-install and Hackage quite well.

ghc-pkg is a lower-level tool for poking GHC's package database. Cabal is intended to work with every Haskell compiler, whereas ghc-pkg is obviously specific to GHC. You can't use ghc-pkg to build anything, you can just register packages you've built otherwise.

like image 96
Miikka Avatar answered Dec 31 '22 20:12

Miikka


cabal is just an interface layer to ghc-pkg with some added features. It's only important to know ghc-pkg because uninstall functionality was not added to cabal, but can be done directly with ghc-pkg.

like image 29
Alex M Avatar answered Dec 31 '22 22:12

Alex M