Proposal: more general unionWith for Data.Map - Summary

The discussion has been over for a month now, so I think it is prudent to summarize the contributions. There have been many suggestions of a general merge function, but the only proposal that matches the expected runtime complexities of the specializations to union/intersection/difference/symmetricDifference came from Jan-Willem Maessen, who suggested a general merge function of the following type: mergeWithKey :: (Ord k) => (k -> a -> b -> Maybe c) -> (Map k a -> Map k c) -> (Map k b -> Map k c) -> Map k a -> Map k b -> Map k c Existing union/intersection/difference and the missing symmetricDifference can be implemented as specialization of this function with no loss to runtime complexity when inlining is used, and even symmetrizing the behaviour of union. Feedback indicated it is worth to unify the existing mess with an abstract foundation, with otherwise no negative reactions. As such, I propose to go through with this. Christian

On Fri, Mar 2, 2012 at 11:16 AM, Christian Sattler < sattler.christian@gmail.com> wrote:
Feedback indicated it is worth to unify the existing mess with an abstract foundation, with otherwise no negative reactions. As such, I propose to go through with this.
My memory is a bit hazy here, but I thought Milan was working on merging this in. Milan? -- Johan

Hi all,
Feedback indicated it is worth to unify the existing mess with an abstract foundation, with otherwise no negative reactions. As such, I propose to go through with this.
My memory is a bit hazy here, but I thought Milan was working on merging this in. Milan?
Yes, I am working on merging mergeWith and mergeWithKey with the type you specified, in Map and IntMap. Hopefully, IntMap.{union*, difference*, intersecion*} and Map.intersection* will be implemented using mergeWith*, depending what the benchmarks reveal. I am not sure about Map.{union*, difference*}, as they use different algorithm -- I am waiting for the benchmarks. Cheers, Milan
participants (3)
-
Christian Sattler
-
Johan Tibell
-
Milan Straka