
6 Feb
2011
6 Feb
'11
1:38 p.m.
On Sat, Feb 5, 2011 at 4:16 PM, Andrew Coppin
Random fact: Data.Map.insertWith' exists. Data.IntMap.insertWith' does *not* exist.
The containers library is a mess. For example, Data.Map has 10+ functions (e.g. adjust) that don't have strict counterparts even though the strict version is most likely what you want. Some functions do allow you to force the value before it's inserted into the map just because you can piggy-back on the evaluation of a constructor e.g. update :: Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a f = update g someKey someMap where g = (\ v -> let v' = v + 1 in v' `seq` Just v') Since the implementation must evaluate the result of g to decide whether to remove the element or not. Johan