iLemming
iLemming

Reputation: 36244

Someone explain Haskell package management system

I just don't get it. It so confusing.

I got that there's ghc-pkg, and Cabal and cabal-install. And these are all different things.

I've been told that installing haskell-platform is a bad idea and it's better to get ghc and cabal-install separately. I don't know though why exactly is that a bad idea.

I found that there's a way to create a sandbox in a local folder using cabal sandbox init. But I don't know how to manage packages globally.

After installing ghc and cabal-install via brew, what's my next step should be? If I do cabal update it would create ~/.cabal directory and probably tell me to upgrade cabal-install by running
cabal install cabal-install. And then I'm gonna have to remove the one installed with brew, and add .cabal/bin to $PATH, so cabal would be pointing to the updated one. So does it mean now if I run cabal install ghc-mod while sitting in home dir it would install libraries in ~/.cabal folder? My ghc-pkg list pointing to /usr/local/Cellar/ghc/7.8.3/lib/ghc-7.8.3/package.conf.d and I don't like that. ghc-pkg list --user points to ~/.ghc/x86_64-darwin-7.8.3/package.conf.d and I don't like that either, but maybe that's fine. Anyway, what's the right way to initialize ghc-pkg? Should I run ghc-pkg init --global | --user or something?

Can you guys tell me what's the right way to manage global dependencies?

Upvotes: 1

Views: 2652

Answers (1)

Shoe
Shoe

Reputation: 76280

I would definitely recommend to install the Haskell Platform. It can be a PITA to update (at least on Mac), but it comes with batteries included and a lot of packages you wouldn't normally get (see System.Random for example).

ghc-pkg is often used to list installed packages.

cabal is used to distribute haskell packages. In practice it's used to build executables or install libraries. You can make a package by creating a .cabal file that will contain the recipe for building/installing your executable/library.

cabal-install is the package that updates cabal.

Sandboxes are extremely important (and they only come with the latests versions of cabal. They are basically like virtualenv for python. In general they create a virtual enviroment in which you can install all the libraries you want without polluting the global system-wide installations. To use them you just need to go into the root of the project you want to build and call cabal sandbox init and then you are done. You can just go on an use cabal install, cabal build, cabal configure, cabal test, like you would normally do. It will automatically detect that it's within a sandbox. If you screw something up you can just delete the sandbox via cabal sandbox delete.

Upvotes: 3

Related Questions