Import
From HaskellWiki
(Difference between revisions)
(rm cases that realistically do not get used) |
|||
Line 35: | Line 35: | ||
| <hask>Mod.x</hask> | | <hask>Mod.x</hask> | ||
| (Only <hask>x</hask>, only qualified.) | | (Only <hask>x</hask>, only qualified.) | ||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| <hask>import Mod hiding (x)</hask> | | <hask>import Mod hiding (x)</hask> | ||
| <hask>y, z, Mod.y, Mod.z</hask> | | <hask>y, z, Mod.y, Mod.z</hask> | ||
| (<hask>x</hask> is hidden.) | | (<hask>x</hask> is hidden.) | ||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| <hask>import qualified Mod hiding (x)</hask> | | <hask>import qualified Mod hiding (x)</hask> |
Revision as of 17:26, 13 February 2007
Theimport
import Data.Maybe
Data.Maybe
However, in more complicated cases, the module can be imported qualified, with or without hiding, and with or without renaming. Getting all of this straight in your head is quite tricky, so here is a table (lifted directly from the language reference manual) that roughly summarises the various possibilities:
Suppose that moduleMod
x
y
z
Import command | What is brought into scope | Notes |
---|---|---|
import Mod |
x, y, z, Mod.x, Mod.y, Mod.z |
(By default, qualified and unqualified names.) |
import Mod () |
(Nothing!) | (Useful for only importing instances of typeclasses and nothing else) |
import Mod (x) |
x, Mod.x |
(Only x y z |
import qualified Mod |
Mod.x, Mod.y, Mod.z |
(Only qualified versions; no unqualified versions.) |
import qualified Mod (x) |
Mod.x |
(Only x |
import Mod hiding (x) |
y, z, Mod.y, Mod.z |
( x |
import qualified Mod hiding (x) |
Mod.y, Mod.z |
( x |
import Mod as Foo |
x, y, z, Foo.x, Foo.y, Foo.z |
(Unqualified names as before. Qualified names use Foo Mod |
import Mod as Foo (x) |
x, Foo.x |
(Only import x |
import qualified Mod as Foo |
Foo.x, Foo.y, Foo.z |
(Only qualified names, using new qualifier.) |