Search code examples
haskellghci

In GHCi, what is the difference between ':module' and 'import'?


In GHCi, there appear to be two ways to include installed modules:

Prelude> :module Database.HDBC
Prelude Database.HDBC>

and

Prelude> import Database.HDBC
Prelude Database.HDBC>

Is there any difference between these? If not, why the duplicate commands?

I've always used import, and now am noticing :module used in Real World Haskell's databases chapter.


Solution

  • From the GHCi docs:

    The :module command provides a way to do two things that cannot be done with ordinary import declarations:

    • :module supports the * modifier on modules, which opens the full top-level scope of a module, rather than just its exports.
    • Imports can be removed from the context, using the syntax :module -M. The import syntax is cumulative (as in a Haskell module), so this is the only way to subtract from the scope.