Search code examples
haskellemacscabal

GHCi cannot find modules of my program


I'm working on a project and I'm using Cabal for management. I've specified directory of source files, modules, all the stuff. All my files have the same names as their corresponding modules, case is preserved.

I can do:

$ cabal configure
$ cabal build

without problems.

However, imagine I have a module Module in file Module.hs, and file File.hs in the same directory. Now, when I'm trying to load File.hs from Emacs for testing, I get the following:

____Could not find module ‘Module’
    It is a member of the hidden package ‘ghc-7.8.3’.
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.

Full contents of File.hs:

module File where
import Module

How to make it find files of my project?


Solution

  • You need to tell GHCi where to find your source files. For example, if your project directory is ./foo and you have your source files in ./foo/src you need to say (from your project directory):

    :set -isrc
    

    at the command prompt in GHCi. You will then have access to private members in your sourc file loaded with C-c C-l.

    You also need to make sure that you haven't cabal installed your package, otherwise the package will be loaded, not the project source files.