Containers and strictness continued

Claus Reinke claus.reinke at
Fri Jul 9 13:22:05 EDT 2010

> You may also want to look at adding monadic inserts/adjusts/etc
> in the sense that there is currently no way to insertWith and extract
> any information in one pass.
> This means a lot of otherwise trivial operations on tries built out of
> Map/IntMap take twice as long as would be otherwise necessary.

Would Data.IntMap.{mapAccumWithKey,insertLookupWithKey} help?

> im

> let upd k f acc key val = if k==key then (Just val,f val) else (acc,val)

> mapAccumWithKey (upd 3 $ const 0) Nothing im
(Just 9,fromList 

> insertLookupWithKey (const $ (+)) 4 4 im
(Just 16,fromList 

> insertLookupWithKey (const $ (+)) 42 4 im

Admittedly, I only remember them because I found them
rather non-obvious when I needed them.. Also, mapAccumWithKey
traverses the whole tree rather than the path to the entry.


More information about the Libraries mailing list