Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get ghci to see packages I installed from cabal?

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.

like image 617
Dominic Cooney Avatar asked Jun 23 '10 13:06

Dominic Cooney


People also ask

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 do I know if GHCi is installed?

Verify that your Installation is Working (On Windows, you probably want Windows Menu → GHCi. Mac and Linux user can just type ghci at a shell prompt.)

What are Haskell packages?

A package is a library of Haskell modules known to the compiler. GHC comes with several packages: see the accompanying library documentation. More packages to install can be obtained from HackageDB.


3 Answers

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.

like image 141
Norman Ramsey Avatar answered Oct 23 '22 06:10

Norman Ramsey


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}.

like image 15
sclv Avatar answered Oct 23 '22 04:10

sclv


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

like image 3
jpaugh Avatar answered Oct 23 '22 06:10

jpaugh