liveBook · Manning

Qualified import

As explained in Learn Haskell by Example

A qualified import is an import declaration that requires definitions from a module to be referenced through that module's name or an alias.

A qualified import makes a module’s definitions available only through the module name or an alias. Write `import qualified Data.AssocMap as M`, then call `M.alter` rather than `alter`. The prefix makes the origin of a definition visible and avoids name clashes between imports. section 5.3.1 section 5.5

import qualified Data.AssocMap as M

This declaration gives `Data.AssocMap` the short qualifier `M`; every imported definition from it must use that prefix. section 5.3.1

Aliases keep qualified code readable. A directed graph can use `M.AssocMap` as its representation and `M.empty`, `M.alter`, and `M.findWithDefault` for map operations, while `Data.List` can be qualified separately as `L` for `L.nub`. section 5.3.1

Separating project modules

A word-ladder module qualifies several modules at once: `Data.List` as `L`, `Graph` as `G`, and `PermutationMap` as `PM`. Calls such as `G.buildDiGraph`, `PM.createPermutationMap`, and `L.map` show which module supplies each operation. section 5.4

Qualification can coexist with selective unqualified imports. A permutation-map module qualifies `Data.AssocMap` and `Data.List`, but imports only `fromMaybe` from `Data.Maybe`; an import list limits which definitions enter scope. section 5.3.2

Use qualification where imported names are likely to collide with each other or with Prelude names. For example, `Data.Text` is qualified as `T` because many of its function names would clash with Prelude imports. section 7.1.1

How Learn Haskell by Example covers it

How deep it goes
Defines aliases and mandatory prefixes, then applies them across graph, permutation-map, and word-ladder modules.
Examples
Uses `Data.AssocMap as M`, `Data.List as L`, a directed graph, permutation maps, and a word-ladder module.
What it assumes
Introduces qualification through import syntax while using modules, functions, and aliases in concrete implementations.
What you can do after
Apply it via Haskell import declarations to use module definitions through clear, collision-resistant prefixes.
How it connects
Connects module imports with aliases, import lists, Prelude hiding, associative maps, directed graphs, and record field-name clashes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.