Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

ghci

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.

like image 970
mherzl Avatar asked Jun 13 '17 21:06

mherzl


People also ask

What is the difference between GHC and Ghci?

Introduction. GHCi is GHC's interactive environment, in which Haskell expressions can be interactively evaluated and programs can be interpreted.

How do I import a module in Haskell?

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.

What is Prelude in Ghci?

Prelude is a module that contains a small set of standard definitions and is included automatically into all Haskell modules.

How do I load a Haskell file into Ghci?

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.)


1 Answers

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.
like image 182
chi Avatar answered Nov 16 '22 02:11

chi