1

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?

  • is it ok that package.conf.d and actual packages are sitting in different folders? What's the role of ~/.ghc folder and ~/.cabal folder?

  • How can one properly uninstall packages? ghc-pkg unregister does not remove the package, right?

    So let's say you installed a package that breaks with the latest version of some other package. Say monad-control. Let's say you do cabal install foo --constraint 'monad-control < 1.0.0.0' and that makes it work. Later you remove "foo" by running ghc-pkg unregister foo and by physically removing related files from .cabal/lib and package.conf.d folder (do you really have to do that manually?). Yet you still have old version of monad-control lying around now. Is there a way to find and prune unused packages?

  • How do you check for outdated packages?

  • Is there a way to see dependencies as a tree? ghc-pkg list gives you just flattened list of packages.

  • why ghc-pkg check throws bunch of warnings like that:

    Warning: haddock-interfaces: ~/.cabal/share/doc/x86_64-osx-ghc-7.8.3/haddock-api-2.15.0.1/html/haddock-api.haddock doesn't exist or isn't a file
    

    I know you can safely ignore those warnings, but what do they mean anyway?

  • finally, don't you guys ever feel that Haskell's packaging system kinda sucks? I know no one should ever criticize something without actually learning, and I am sorry for saying that. I am very newbie in Haskell, yet I feel default package management of Haskell is full of shortcomings. I'm wondering if there's better alternative that I don't know about? Haskell's been around for quite some time, I heard talks about package management that should not rely on concrete packages, but should be based on abstractions, like interfaces. Wondering, if soon we'd have this kind of packaging system? Or that's just theoretical academical rhetorics and that won't see the light until sometime in 2020?

iLemming
  • 34,477
  • 60
  • 195
  • 309
  • "And then I'm gonna have to remove the one installed with brew" There's really no need to do this. Leave that there in case you wipe out your local `~/.cabal` so you still have a backup Cabal available. Regarding the Haddock warnings, you can [ignore them](http://stackoverflow.com/q/22554498). Lastly, you cannot uninstall packages with Cabal: `ghc-pkg unregister` causes the package to disappear as far as GHC is concerned but it will still eat up your disk space. – Rufflewind Dec 28 '14 at 09:28

1 Answers1

3

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.

Shoe
  • 74,840
  • 36
  • 166
  • 272
  • 2
    you still haven't answered my question. let's say I want to install ghc-mod to use in both Emacs and Sublime-Text. It needs to be installed globally, right? Or something like hoogle. Do you need to create "global sandbox" for these? I don't think so, right? So what's the proper way to manage global packages? – iLemming Dec 28 '14 at 08:09
  • @Agzam Remove everything you have installed so far. Install the Haskell Platform. Install the packages you want without sandboxes. ???. Profit. – Shoe Dec 28 '14 at 08:19
  • No I don't want to install the platform. You said it yourself - updating it is PITA. Writing down that question actually I think helped me to understand the system a bit better. Right now I have a problem - ghc-mod fails to install and it seems the problem is either in monad-journal or monad-control. I need to try installing it with specific constraints – iLemming Dec 28 '14 at 08:32
  • @Agzam: You don't really want to install things globally except for the bare essentials. This is to reduce the damage when things break, since you can always just clear out your local `~/.cabal` and `~/.ghc` when things go haywire. (And to be honest, things can break a lot in the Hackage ecosystem because everything is bleeding edge and Cabal still needs some work, but it's gotten better lately!) There's no reason `ghc-mod` needs to be installed globally — in fact if you look at their website it shows how it's to be installed in your home directory! – Rufflewind Dec 28 '14 at 09:27
  • @Rufflewind oh, now I see. There's 3 different types: global, home dir and sandbox. I was confused. So whenever I said globally, I meant home dir – iLemming Dec 28 '14 at 09:37
  • So then how .cabal folder in home dir different from .cabal folder in any other dir? If I run `cabal install foo` from inside a folder (e.g. "myDir" - not home) that has `.cabal` folder in it (not .cabal-sandbox) do packages get installed into `~/.cabal` or `myDir\.cabal`? – iLemming Dec 28 '14 at 09:42
  • @Agzam: there shouldn't be a `.cabal` directory in random places. There should be only one for each user under `~/`. Did you confuse it with the `my-project.cabal` *file* that appears in each Cabal package? – Rufflewind Dec 28 '14 at 10:07