views:

83

answers:

3

I've installed the such-and-such a package using cabal, and I can build a program that depends on it using cabal build. But when I load the same program in ghci, ghci complains that it "Could not find module `such-and-such'".

I'm surprised this doesn't "just work." How do I tell ghci where to find the packages I've installed with cabal?

Here's my setup: I'm using GHC 6.10.4 on Mac OS X 10.6.3, cabal-install version 0.6.2 using version 1.6.0.3 of the Cabal library.

+1  A: 

ghc-pkg list on the command line will tell you what your installed packages are. The installed package might be hidden, in which case you can reveal it with ghc-pkg expose {pkg-id}.

sclv
Here is what that outputs: bash-3.2$ ghc-pkg list lrucache /opt/local/lib/ghc-6.10.4/./package.conf: /Users/dominic/.ghc/x86_64-darwin-6.10.4/package.conf: lrucache-1.0How do I go from that, to where the package *is*? And then do I use `ghci -i`?
Dominic Cooney
Yes! `ghc-pkg register such-and-such` is indeed the required magic. Thanks!
Dominic Cooney
You probably want to change your cabal prefs to do global registers. Change ~/.cabal/config to say `user-install: False`.
sclv
+2  A: 

You need

ghci -package such-and-such

And to double-check that such-and-such is truly visible to GHC, run ghc-pkg list | grep such-and-such.

Norman Ramsey
I'm preferring this answer since I'd rather not clutter up the global package namespace with exposed packages.Bonus round: *In* ghci, how do I dynamically add a package?
Dominic Cooney
A: 

I would like to go further in this question: I often encounter useless reinstallation of packages throught cabal

I'm trying to install Chart (it happens also on many other packages: this is just an example to show what's happening)

if I do a cabal install Chart, it installs me process, random and haskell98 althought I already have it systemwise installed:

ghc-pkg list|sort|uniq -c |sort|tail                                             
  1     X11-xft-0.3
  1     xdg-basedir-0.2
  1     xhtml-3000.2.0.1
  1     xmonad-0.9.1
  1     xmonad-contrib-0.9.1
  1     zlib-0.5.2.0
  2 
  2     haskell98-1.0.1.1
  2     process-1.0.1.2
  2     random-1.0.0.2

If I try to relaunch a cabal install Chart, it again reinstalls process, random and haskell98

Now if I untar the downloaded package (in cabal dir), and I'm trying to compile it directly:

[~/.cabal/packages/hackage.haskell.org/Chart/0.13.1/Chart-0.13.1] runhaskell Setup.hs configure                                                    
Configuring Chart-0.13.1...                                                           
Setup.hs: At least the following dependencies are missing:
colour >=2.2.1,
data-accessor ==0.2.*,
data-accessor-template >=0.2.1.1 && <0.3

and these packages are registered in ghc:

ghc-pkg list|grep accessor                                                                                                              
data-accessor-0.2.1.3
data-accessor-0.2.1.4
data-accessor-monads-fd-0.2.0.2
data-accessor-template-0.2.1.4

and

ghc-pkg list|grep colour                                                                                                                 
colour-2.3.1

Can you help me to understand what's happening?

By default cabal installs in user space (but that's ok with me)

I'm running a debian squeeze distribution with haskell and ghc installs through package manager

Thanks Louis

Louis