Tshimanga
Tshimanga

Reputation: 885

Loading Haskell Modules that have dependencies

I'm unsure what my issue is here. I have a trio of modules A.hs, B.hs, and C.hs. All are located at C:\..path...\folder and modules B and C both import from A.

That is, both modules B and C contain the line import A

I can :l C:\..path..\folder\A.hs in gchi and play with its contents; however, ghci gives the following error when I try to :l C:\..path..\folder\B.hs or :l C:\..path..\folder\C.hs

    Could not find module `A'
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.

Which I find odd because I had no trouble compiling B.hs to B.exe and running the executable. How can I compile and run a module that I can't load into ghci? Or, why would an import succeed at compile time but fail in loading; especially when that very module being imported is itself load-able?

Upvotes: 3

Views: 501

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 152682

By default, ghci searches only in the current directory for imported modules. To start with, the current directory is the one used to launch ghci; but it can be changed from within ghci with the :cd command. Thus, you could

> :cd C:\...path...\folder
> :l B.hs

and this should find both B.hs and A.hs in what is now the current directory. Alternately (and especially if you have modules in multiple directories) you can launch ghci with the -i command line option to add directories to its module search path. For example, in your command prompt you might

% ghci -iC:\...path...\folder
> :l B.hs

which will instruct ghci to include C:\...path...\folder in its search path, and therefore find B.hs and A.hs there even if it is not the current directory.

Upvotes: 5

Related Questions