Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'qualified' mean in 'import qualified Data.List' statement?

Tags:

haskell

I understand import Data.List.

But what does qualified mean in the statement import qualified Data.List?

like image 914
Optimight Avatar asked Jun 30 '12 14:06

Optimight


2 Answers

A qualified import makes the imported entities available only in qualified form, e.g.

import qualified Data.List  result :: [Int] result = Data.List.sort [3,1,2,4] 

With just import Data.List, the entities are available in qualified form and in unqualified form. Usually, just doing a qualified import leads to too long names, so you

import qualified Data.List as L  result :: [Int] result = L.sort [3,1,2,4] 

A qualified import allows using functions with the same name imported from several modules, e.g. map from the Prelude and map from Data.Map.

like image 121
Daniel Fischer Avatar answered Oct 05 '22 20:10

Daniel Fischer


If you do an unqualified import (the default), you can refer to anything imported just by its name.

If you do a qualified import, you have to prefix the name with the module it's imported from.

E.g.,

import Data.List (sort) 

This is an unqualified import. You can now say either sort or Data.List.sort.

import qualified Data.List (sort) 

This is a qualified import. Now sort by itself doesn't work, and you have to say Data.List.sort.

Because that's quite lengthy, normally you say something like

import qualified Data.List (sort) as LS 

and now you can write LS.sort, which is shorter.

like image 26
MathematicalOrchid Avatar answered Oct 05 '22 20:10

MathematicalOrchid