
6 Sep
2006
6 Sep
'06
6:51 a.m.
John Goerzen wrote:
+-- | Strict version of 'insertWith'. +insertWith' :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a +insertWith' f k v m + = case lookup k m of + Nothing -> insert k v m + Just w -> (insert k $! f w v) m + }
Dunno if the Data.Map you're patching is the one using AVL trees, but if so I would advise against this implementation as it requires two searches for the key. The AVL library already contains functions to do this with only one search (just needs the appropriate wrapper writing). Regards -- Adrian Hey