addListToFM

Christian Maeder maeder at tzi.de
Fri Jun 3 07:51:20 EDT 2005


Serge D. Mechveliani wrote:
> I used to apply  FiniteMap.addListToFM.
> Now, what is its best expression in ghc-6.4 ?
> Is this 
>         \ mp pairs -> Map.union (Map.fromList pairs) mp
> ?
> (the order of the arguments in Map.union is essential). 

This looks fine to me. "best" is hard to meet. I'ld suggest:

  foldr (uncurry Map.insert)

Efficiency should be tested, though.

Cheers Christian

P.S.

Data.Map contains the following definition:

fromList xs
  = foldlStrict ins empty xs
  where
    ins t (k,x) = insert k x t





More information about the Glasgow-haskell-users mailing list