0
votes

I have a situation where ghc-mod can't find a module installed in my ~/.ghc/ directory.

The program (foo.hs) is just:

import Control.Monad.Loops
main = undefined

ghci loads foo.hs without any errors.

ghc-pkg list produces the output:

/Library/Frameworks/GHC.framework/Versions/7.8.3-x86_64/usr/lib/ghc-7.8.3/package.conf.d
    Cabal-1.18.1.4
    GLURaw-1.4.0.1
    ...
~/.ghc/x86_64-darwin-7.8.3/package.conf.d:
    ...
    monad-loops-0.4.2.1

but ghc-mod check foo.hs errors out with:

x.hs:4:8:Could not find module ‘Control.Monad.Loops’Perhaps you meant  Control.Monad.Cont (from mtl-2.1.3.1)  Control.Monad.List (from mtl-2.1.3.1)  Control.Monad.Trans (from mtl-2.1.3.1)Use -v to see a list of the files searched for.

ghc-mod is located in ~/Library/Haskell/bin and ghc-mod -v emits:

ghc-mod version 5.0.1.2 compiled by GHC 7.8.3
...

What's kinda odd is that I don't get an error when loading foo.hs in Emacs under haskell-mode, and presumable that also uses ghc-mod.

Is there a way to debug this further and/or configure ghc-mod to look in my ~/.ghc directory?

1
Is this part of a cabal project? If so there's a bug in the current ghc-mod which may require a "cabal clean" if you've changed the installed packages at all.Shaun the Sheep
No - I don't have a cabal file in the directory.ErikR
Cabal is usually the easiest and safest way to go when installing user libraries. If you add a cabal file, point it at your foo.hs, and run cabal install, you should be good to go. You'll need to add monad-loops as a dependency in the cabal file as well, but cabal init, which will create a skeleton file for you can sometimes figure this out for you from your code.bheklilr

1 Answers

1
votes

The answer is that ghc-mod will look for a cabal.sandbox.config file in all parent directories of the current working directory and use that if it finds one, and that was hiding my ~/.ghc package directory.