[Haskell-cafe] Problem with Data.Map

minh thu noteed at gmail.com
Mon Jun 8 13:00:08 EDT 2009


> import Blurp
bring every thing defined in the Blurp module in scope.
So if blah is defined in blurp,
> blah
will work as expected.

> import qualified Blurp as B
does the same thing but everything defined in Blurp should be
qualified (i.e. prefixed) with B.
> B.blah
will work, not
> blah

So your import statement is right but you should write Map.fromList
instead of just fromList.

The goal is to have multiple identical names from different modules
and still be able to use them at the same time, but qualified, for
instance lookup is defined in both Data.List and Data.Map.

> import qualified Data.List as L
> import qualified Data.Map as M
> L.lookup
> M.lookup
The two last lines are unambiguous.


2009/6/8 michael rice <nowgate at yahoo.com>:
> I don't understand your response. I copied the imports from Hoogles Data.Map
> page. What should the imports be?
> Michael
> --- On Mon, 6/8/09, Jochem Berndsen <jochem at functor.nl> wrote:
> From: Jochem Berndsen <jochem at functor.nl>
> Subject: Re: [Haskell-cafe] Problem with Data.Map
> To: "michael rice" <nowgate at yahoo.com>
> Cc: haskell-cafe at haskell.org
> Date: Monday, June 8, 2009, 12:45 PM
> michael rice wrote:
>> I'm trying to understand Map type for possible use in another problem I'm
>> working on, but am stymied right off the bat.
>> ==========Here's my source:
>> import Data.Map (Map)
>> import qualified Data.Map as Map
>> *Main> fromList $ zip l1 l2
>> <interactive>:1:0: Not in scope: `fromList'
> You imported map "qualified as Map", that means that only 'Map.fromList'
> and 'Data.Map.fromList' are in scope, and not 'fromList'. The reason one
> normally does it like this is that a lot of function names clash with
> the Prelude (on purpose). Normally one uses "qualified as M" or
> "qualified as Map" to shorten the notation.
> HTH,
> --
> Jochem Berndsen | jochem at functor.nl
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list