29 Jul 13:39 2013

## Data.Map, unionWithMaybe

Sebastiaan Joosten <sjcjoosten <at> gmail.com>

2013-07-29 11:39:13 GMT

2013-07-29 11:39:13 GMT

Dear libraries, for Data.Map, I needed a "unionWithMaybe" function for my sparse system of linear equations (unionWithMaybe :: Ord k => (a -> a -> Maybe a) -> Map k a -> Map k a -> Map k a). My usage: (.+.) = Map.unionWithMaybe (\a b->case a+b of {0->Nothing;s->Just s}) (I do not think Map.unionWithMaybe can be expressed in terms of other functions without loosing performance, so I recon it would be a nice addition to the library.) I built this function myself by modifying the Data.Map implementation, but it would be nice to see it in the official version of Data.Map. Here is the file including the modifications I made to it. Feel free to use it, I will agree to whatever license you need to make it public. (PS: this is the first time I return modified source code to the maintainer, feel free to instruct me on how to do this in the future.) Sincerely, Sebastiaan J.C. Joosten {-# OPTIONS_GHC -XNoBangPatterns -cpp -XStandaloneDeriving -XDeriveDataTypeable #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Map -- Copyright : (c) Daan Leijen 2002 -- (c) Andriy Palamarchuk 2008 -- License : BSD-style -- Maintainer : libraries <at> haskell.org -- Stability : provisional -- Portability : portable -- -- An efficient implementation of maps from keys to values (dictionaries). --(Continue reading)