[Haskell-beginners] Using GHCi, import submodule that needs to import another submodule?

James Toll james at jtoll.com
Wed Mar 5 21:11:06 UTC 2014

On Mar 5, 2014, at 1:18 PM, Daniel Trstenjak  wrote:
> Hi James,
>> So import still does not work.  But by trying “:load" from the parent
>> directory, I was able to load Sphere, Cube and Cuboid.  The problem is
>> that it appears that only one is available at a time (i.e. loading
>> Cube displaces Sphere). What’s more there is no way to do qualified
>> imports.
> Sorry about this one. 'import' depends on the available/installed ghc packages,
> the given module name 'Geometry.Sphere' is looked up in these packages.
> Calling 'ghc-pkg list' will give you a list of all packages.
> If you don't have created and installed a package for your geometry
> files, then ghci will not know them.
> So calling ':load/:add' is the right thing here.

Daniel et al.,

Thank you for the clarification. No worries.  I appreciate you taking the time to respond to my question.

One observation I could make as a beginner is that I wish the documentation made a better distinction between packages and modules.  I suppose the ambiguity from my standpoint (please correct me if I’m wrong) is that all packages are, or include, modules, but not all modules are packages.  As such, import would only be used for installed packages and not for my own modules.  But the documentation for import routinely makes reference to modules, leading myself to incorrectly believe that I could import my own local modules using import.

I’ve been reading through the page regarding scope that Brent referenced and feel as though it has clarified a few things, but also raised many more questions.  Unfortunately it doesn’t make a clear distinction between packages and modules either.   

From http://www.haskell.org/ghc/docs/7.6.3/html/users_guide/interactive-evaluation.html#ghci-scope :module and :load
I’d love to get a clear definition of “loaded" vs "in scope".  Does import only bring a module into scope, not load it?  Then would installed packages be considered loaded but not in scope?  But they don’t show up with :show modules.  Would using import then place them in scope?  My personal modules would be neither loaded, nor in scope?  Using :load loads them and also places them in scope?  Using :modules -m would remove a module from scope but it would still be loaded?

Lots and lots of questions.  If anyone has any links to documentation that would clear up some of these questions, I’d appreciate it.  Anyway, it appears that using import is not possible for my modules, only for installed packages, so using :load and :add are the correct solution.

Thanks again for the help,


More information about the Beginners mailing list