Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're right that <code>import Module</code> and <code>:module + Module</code> are identical, but there are a few reasons for the <code>:module</code> (henceforth abbreviated <code>:m</code>) syntax.</p> <ol> <li><p>It's older. GHCi really used to just be the inside of an <code>IO</code> <code>do</code> block; now it supports every part of the language, so we can do <code>import</code>s. (It looks like <a href="http://www.haskell.org/ghc/docs/6.6-latest/html/users_guide/ch03s04.html#ghci-scope" rel="noreferrer">GHCi 6.6.x didn't support <code>import</code></a>, but <a href="http://www.haskell.org/ghc/docs/6.8.1/html/users_guide/interactive-evaluation.html#ghci-scope" rel="noreferrer">GHCi 6.8.1 did</a>; we didn't get full support for top-level declarations until <a href="http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/interactive-evaluation.html#ghci-decls" rel="noreferrer">GHCi 7.4.1</a>.)</p></li> <li><p>It lets you import multiple modules at once. <code>:m + M1 M2 M3</code> is the same as writing <code>import M1</code>, <code>import M2</code>, and <code>import M3</code> each on a new line.</p></li> <li><p>It lets you un-import modules: <code>:m - M</code> will remove <code>M</code>'s contents from what's currently in scope at the prompt.</p></li> <li><p>It lets you import an interpreted module so that you can see the <em>whole</em> scope. This is what happens when you <code>:load File.hs</code>; you find that you're in the module <code>*File</code>, and can <em>e.g.</em> see everything that <code>File</code> imports and even everything that it doesn't export. If you have an interpreted module <code>MI</code> loaded, then you can use <code>:m + M1 *MI M3</code> to bring <code>M1</code> and <code>M2</code> into scope the ordinary way, and <code>MI</code> into scope the special way.</p></li> </ol> <p>For completeness, though, <code>import</code> syntax does offer us three things that <code>:m</code> doesn't:</p> <ol> <li><p>Qualified imports. It's much nicer to be able to do <code>import qualified Data.Map as M</code> and use <code>M.lookup</code> than to have to do <code>Data.Map.lookup</code> or suffer ambiguity errors. (Note that every package that's installed is available fully qualified in GHCi, so <code>import qualified Module</code> alone buys you nothing.)</p></li> <li><p>Import lists. Even if I have the functions from <code>Data.Map</code> qualified with <code>M</code>, I can still do <code>import Data.Map (Map)</code> to just bring the type into scope unqualified.</p></li> <li><p>Import <code>hiding</code>. The reverse of the above; maybe I'm writing my own sorting routine, so I can do <code>import Data.List hiding (sort)</code>.</p></li> </ol> <p>You can also check out <a href="http://www.haskell.org/ghc/docs/7.6-latest/html/users_guide/interactive-evaluation.html#ghci-scope" rel="noreferrer">§2.4.5, "What's really in scope at the prompt?", in the GHC (7.6) user's guide</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload