darcs patch: Added Data.Map.insertWith'

Tue Sep 5 13:11:49 CDT 2006 John Goerzen

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

I had decided to add such a function, though I never had come to do it.
My only worry is that if you want a consistent API you'll need a bunch
of functions with a strict version.
Cheers,
JP.
On 9/5/06, John Goerzen
Tue Sep 5 13:11:49 CDT 2006 John Goerzen
* Added Data.Map.insertWith' Use of insertWith can lead to memory leaks. This function was suggested by Udo Stenzel at http://article.gmane.org/gmane.comp.lang.haskell.cafe/14864 This type of algorithm solved a real problem discussed in this thread:
http://thread.gmane.org/gmane.comp.lang.haskell.cafe/14852
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

I just pushed a more efficitent version.
Cheers,
JP.
On 9/5/06, John Goerzen
Tue Sep 5 13:11:49 CDT 2006 John Goerzen
* Added Data.Map.insertWith' Use of insertWith can lead to memory leaks. This function was suggested by Udo Stenzel at http://article.gmane.org/gmane.comp.lang.haskell.cafe/14864 This type of algorithm solved a real problem discussed in this thread:
http://thread.gmane.org/gmane.comp.lang.haskell.cafe/14852
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
participants (3)
-
Adrian Hey
-
Jean-Philippe Bernardy
-
John Goerzen