Haskell / GHCi - loading modules from different directories

simon picture simon · Jul 7, 2011 · Viewed 9k times · Source

My haskell application has the following directory structure:

src/
    utils/Utils.hs
    subsystem/Subsystem.hs

The Subsystem module imports Utils module. I would like to hand test this code in GHCi.

The problem is GHCi seems to be only looking for modules available in '.' (current directory), so I copied Utils.hs to subsystem folder and was able to hand-test Subsytem.hs. Is there a better way to do this? For example I would like to start GHCi in the src directory and let it search for modules in ./utils and ./subsystem directories. Can I specify a module path to GHCi?

Answer

hammar picture hammar · Jul 7, 2011

You can tell GHCi where to search for modules by using the -i option:

ghci Foo.Bar -isrc

This will load src/Foo/Bar.hs into GHCi. This way, you can also specify two different directories like this:

ghci Bar.hs -i.:config 

It will look for the dependencies in ./ and ./config/ .

See the GHC user's guide for more information about the module search path.