runghc -package-db=.cabal-sandbox/.cabal-sandbox/x86_64-osx-ghc-7.8.3-packages.conf.d hellowai.hs
Works perfect for me.
Similarly, with
ghci -package-db=.cabal-sandbox/.cabal-sandbox/x86_64-osx-ghc-7.8.3-packages.conf.d
I am also able to import my cabal-sandbox-installed Wai
package in ghci
with no issue at all.
But when I ask ghc-mod
to validate my haskell source code, via
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 is unable to find my cabal sandbox installed module. Why is that so?
Do you have a
cabal.sandbox.config
file? And are you using a.cabal
file for your project?If you have both of these you should be able to use
ghc-mod check ...
and it will just work.Another advantage of using a .cabal file is that you can use
cabal repl
to invoke ghci andcabal run
to invokerunhaskell
with the correct command line options.Update
Here is a recipe you can try out to see when ghc-mod can find your cabal sandbox. Perhaps this can help you determine what's different with your set up.
Start in a clean directory:
Edit around line 55 of split.cabal to add
heredoc
as a dependency.Edit src/Data/List/Split.hs to use the module
Text.Heredoc
:Make sure
heredoc
is installed:Finally this should work:
And it will still work if you cd into a sub-directory:
However, ghc-mod won't work if you move away
split.cabal
:In this case I created the sandbox in a parent directory of our working directory, but things should also work if the initial sandbox was created like this: