Reputation: 547
There are several things I'm confused about here, so I'll try to explain each of them as clearly as I can.
I've been trying to install the diagrams
package for haskell, using cabal. I've seen it suggested to install packages using sandboxes, so that's what I did. Something that's not clear to me is exactly what a sandbox is - I understand that I can initialise one with cabal sandbox init
and install packages inside of it with cabal install
, but I don't see how to use those packages once they're installed.
I then tried to compile a test-script using ghc, which resulted in the following error:
diagramstutorial.lhs:3:10:
Could not find module 'Diagrams.Prelude'
Use -v to see a list of the files searched for.
With a similar error for another module that the script was supposed to load. These modules are definitely both included in the diagrams package, and cabal seems happy that the package is installed correctly. I expect there's something simple I just don't understand, but I don't know what it is.
Upvotes: 0
Views: 1569
Reputation: 2237
Find the sandbox directory, and locate the packages.conf.d
file.
For example, /home/user/.cabal-sandbox/x86_64-linux-ghc-7.8.4-packages.conf.d
Rerun your GHC commands with the package-db
flag:
ghci -package-db /home/user/.cabal-sandbox/x86_64-linux-ghc-7.8.4-packages.conf.d --make diagramstutorial.lhs
Everything should now work
Upvotes: 1
Reputation: 34378
I typed
ghc --make diagramstutorial.lhs
to compile it
That will make GHC use the regular user package database (that is, not the sandbox one). Use cabal exec -- ghc --make diagramstutorial.lhs
instead, so that GHC runs in the context of your sandbox.
You can also use GHCi within the sandbox with cabal repl
. And naturally, if/when you start preparing a cabal package, all cabal commands (cabal build
, etc.) will use the sandbox if you are within its directory.
Something that's not clear to me is exactly what a sandbox is
A set of packages with an accompanying database local to the directory. Beyond the cabal.sandbox.config
configuration file there is also a hidden directory .cabal-sandbox
, in which diagrams
and the other packages you installed lie.
Upvotes: 2