
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). Thank you in advance for explanation. ----------------- Serge Mechveliani mechvel@botik.ru

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

On Jun 3, 2005, at 7:51 AM, Christian Maeder wrote:
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)
The trouble is, neither of these approaches is demonstrably better for *all* finitemap implementations. The latter is probably best for standard binary trees with a balance metric, where union is notoriously difficult. But for other structures the union approach may work better (a randomly-balanced tree I'm fiddling with has this property, I think). That argues for presence in the library. -Jan-Willem Maessen
participants (3)
-
Christian Maeder
-
Jan-Willem Maessen
-
Serge D. Mechveliani