Importing Modules

This is sort of basic grammars, so I just use snippets to show how. Suppose in Module, we have functions foo, bar and datatype Maybe

Basic import
1
2
3
4
import Module

-- Then we can use normally
foo ...

Qualified import allows one to separate different namespaces, to enhance maintainability.

Qualified import
1
2
3
4
import qualified Module

-- Then we have to add module name before calling function
Module.foo ...

We may also add aliases for modules imported.

Aliased import
1
2
3
4
import qualified Module as M

-- Then we use alias to call
M.foo

We can select a part to import.

Selective import
1
2
3
4
5
6
7
import Module (foo)

-- Then we can use foo, but not bar
foo ...

-- We can selectively import datatype, along with their constructors
import Module (Maybe(..)) -- use Type(..)

Managing Modules with Cabal

Cabal is shipped with GHCup as project manager.