Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 960
Mark Karpov Avatar asked Oct 17 '14 06:10

Mark Karpov


2 Answers

You can launch the REPL via Cabal like so:

# cabal repl

This is the same as running ghci, but will take into account any additional dependencies installed by cabal install your local or sandbox package repository.

like image 127
James Davies Avatar answered Oct 13 '22 00:10

James Davies


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.

like image 39
vivian Avatar answered Oct 12 '22 23:10

vivian