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.
Introduction. GHCi is GHC's interactive environment, in which Haskell expressions can be interactively evaluated and programs can be interpreted.
The syntax for importing modules in a Haskell script is import <module name>. This must be done before defining any functions, so imports are usually done at the top of the file. One script can, of course, import several modules. Just put each import statement into a separate line.
Prelude is a module that contains a small set of standard definitions and is included automatically into all Haskell modules.
Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)
From the GHCi docs:
The
:module
command provides a way to do two things that cannot be done with ordinaryimport
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
. Theimport
syntax is cumulative (as in a Haskell module), so this is the only way to subtract from the scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With