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

Daniel Trstenjak daniel.trstenjak at gmail.com
Thu Mar 6 10:06:36 UTC 2014


Hi James,

> One observation I could make as a beginner is that I wish the
> documentation made a better distinction between packages and modules.

Unfortunately it's even a bit more complex. 

First of all there're the cabal packages which contain your haskell
source files which define the modules.

These cabal packages are build and installed by cabal and result into
ghc packages, which are some kind of binary blob (I don't know the details)
that contains all your modules in a compiled form, and these packages
are readable by ghc/ghci.

So 'import' refers to the modules of the ghc packages and ':load' refers
to the modules in the source files.

> 2.4.5.1. :module and :load I’d love to get a clear definition of “loaded" vs "in scope".

':load' is pretty much the same as loading a package and importing a
module from it, so ':load' does both at once.

Everything that's imported is in scope.


> Does import only bring a module into scope, not load it?

You've to load something before you can bring it with import into scope.


> Then would installed packages be considered loaded but not in scope?

I think that ghci only loads and imports the packages defining the Prelude module at startup.
All other packages are loaded lazily if you're importing a module of them.


> Using :load loads them and also places them in scope?

Yes.


> Using :modules -m would remove a module from scope but it would still be loaded?

I think so for ghc package modules, but I'm not sure for modules loaded with ':load',
they might get unloaded again, but even if not, I don't think that you could get them back
in scope by using 'import'.


Greetings,
Daniel


More information about the Beginners mailing list