Lesson 45 of 55
9 mins readPython Modules, Exports & Qualified Imports
In Plain English
Haskell code is organized into modules. Use module Name (exportedFunctions) where to declare modules, and import qualified Data.Map as Map to avoid name clashes.
Deep Dive: How It Works
Module Header: module Geometry.Sphere (volume, area) where.
Explicit Imports: import Data.List (sort, nub) brings only specified functions into scope.
Qualified Imports: import qualified Data.Map as Map requires calling Map.lookup and Map.insert, preventing collisions with Prelude.lookup.
Core Rules to Remember

Explicit Export Lists: Control your public API by exposing only intended functions and types.

Qualified Imports: Avoid symbol name collisions across libraries with import qualified ... as.
Live Interactive Example
Hit Run Code to see it liveExplicit and Qualified Imports
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Output Console
Click "Run Code" to view the rendered output.
How it works: nub removes duplicates; Map.lookup performs a key-value search.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Remove Duplicates with nub
Import `Data.List (nub)` and apply to `[1, 1, 2, 3, 3]`.
Print `"Unique: "` followed by its `show` string.
1
2
3
4
5
6
7
8
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.