I understand import Data.List
.
But what does qualified
mean in the statement import qualified Data.List
?
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With