33

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.

Dominic Cooney
  • 6,317
  • 1
  • 26
  • 38

3 Answers3

23

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
  • 198,648
  • 61
  • 360
  • 533
  • 1
    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 Jun 25 '10 at 01:24
  • 2
    `:set -package haskell-src-meta` works. I think you can set any `ghci`/`ghc` flag with `:set`. Like `:set -XTemplateHaskell`. – sam boosalis Nov 12 '14 at 04:43
15

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
  • 38,665
  • 7
  • 99
  • 204
  • 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.0 How do I go from that, to where the package *is*? And then do I use `ghci -i`? – Dominic Cooney Jun 23 '10 at 14:13
  • Yes! `ghc-pkg register such-and-such` is indeed the required magic. Thanks! – Dominic Cooney Jun 23 '10 at 14:30
  • You probably want to change your cabal prefs to do global registers. Change ~/.cabal/config to say `user-install: False`. – sclv Jun 23 '10 at 15:18
4

Use cabal repl to ask cabal to open the GHCi interpreter with all the right settings for your project.

jpaugh
  • 6,634
  • 4
  • 38
  • 90