Import
From HaskellWiki
Theimport
import Data.Maybe
Data.Maybe
However, there are more options: 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,y) | x, y, Mod.x, Mod.y | (Only x y z |
| import qualified Mod | Mod.x, Mod.y, Mod.z | (Only qualified versions; no unqualified versions.) |
| import qualified Mod (x,y) | Mod.x, Mod.y | (Only x y |
| import Mod hiding (x,y) | z, Mod.z | ( x y |
| import qualified Mod hiding (x,y) | Mod.z | ( x y |
| 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,y) | x, y, Foo.x, Foo.y | (Only import x y |
| import qualified Mod as Foo | Foo.x, Foo.y, Foo.z | (Only qualified names, using new qualifier.) |
Prelude
zip
module Mod where import Prelude hiding (zip) zip = {- ... -}
import
zip
module Mod where import qualified Prelude as P zip = {- ... -}
P.show (2 P.+ 3 P.* 3) P.++ "abc"
Note that any module using a module that redefines prelude functions will need to import either the prelude or the other module (or maybe both) qualified and/or with hiding for the same reason.
See also
- Import modules properly - Some thoughts that may help to decide what form of the import statement to use.
