Ghc-mod doesn't use my sandbox. What for?
runghc -package-db=.cabal-sandbox/.cabal-sandbox/x86_64-osx-ghc-7.8.3-packages.conf.d hellowai.hs
Perfect for me.
Similarly, for
ghci -package-db=.cabal-sandbox/.cabal-sandbox/x86_64-osx-ghc-7.8.3-packages.conf.d
I can also import the package Wai
installed in cabal-sandbox into ghci
without any problem.
But when I ask ghc-mod
to check my haskell source code,
ghc-mod check --boundary="" -g -package-db=.cabal-sandbox/x86_64-osx-ghc-7.8.3-packages.conf.d hellowai.hs
hellowai.hs:4:8:Could not find module ‘Network.Wai.Handler.Warp’Use -v to see a list of the files searched for.
hellowai.hs:3:8:Could not find module ‘Network.HTTP.Types’Perhaps you meant Network.HTTP.Base (from HTTP-4000.2.19) Network.HTTP.Base (needs flag -package HTTP-4000.2.10) Network.HTTP.Headers (needs flag -package HTTP-4000.2.10)Use -v to see a list of the files searched for.
hellowai.hs:2:8:Could not find module ‘Network.Wai’Perhaps you meant Network.BSD (needs flag -package network-2.4.2.3) Network.URI (needs flag -package network-2.4.2.3) Network.TCP (needs flag -package HTTP-4000.2.10)Use -v to see a list of the files searched for.
It cannot find the installed cabal sandbox module. Why is this so?
source to share
Do you have a file cabal.sandbox.config
? And are you using the file .cabal
for your project?
If you have both of them, you will be able to use ghc-mod check ...
and it will work.
Another advantage of using a .cabal file is that you can use cabal repl
ghci cabal run
to invoke and to invoke runhaskell
with the correct command line parameters.
Update
Here's a recipe you can try to see when ghc-mod can find your sandboxed sandbox. Perhaps this will help you determine what is different from your setup.
Run in a clean folder:
$ mkdir foo
$ cd foo
$ cabal sandbox init
$ cabal get split
$ cd split-0.2.2
$ cabal sandbox init --sandbox=../.cabal-sandbox
Edit line 55 split.cabal to add heredoc
as a dependency.
Modify src / Data / List / Split.hs to use the module Text.Heredoc
:
{-# LANGUAGE QuasiQuotes #-}
...
import Text.Heredoc
...
foo :: String
foo = [here|this is a test|]
Make sure to install heredoc
:
$ cabal install --only-dependencies
Finally, this should work:
$ ghc-mod check ./src/Data/List/Split.hs
And it will work if you cd into a subdirectory:
$ cd src
$ ghc-mod check ./Data/List/Split.hs
However, ghc-mod won't work if you leave split.cabal
:
(back at the top level directory)
$ mv split.cabal split.cabal-old
$ ghc-mod check ./src/Data/List/Split.hs
In this case, I created a sandbox in the parent directory of our working directory, but everything should work if the initial sandbox was created like this:
$ mkdir foo
$ cd foo
$ mkdir sandbox-dir
$ cd sandbox-dir
$ cabal sandbox init
$ cd ..
$ cabal get split
$ cd split-0.2.2
$ cabal sandbox init --sandbox=../sandbox-dir/.cabal-sandbox
source to share