Proposal: more general unionWith for Data.Map
fox at ucw.cz
Tue Jan 24 22:25:57 CET 2012
> On Tue, Jan 24, 2012 at 11:58 AM, Milan Straka <fox at ucw.cz> wrote:
> > FYI, the new intersectionWithKey is not released yet -- maybe we could
> > leave intersectionWithKey as it is, and provide mergeWith[Key] instead.
> > Opinions?
> I think so. We should avoid the words union and intersection if they
> don't correspond to the mathematical idea, or we risk confusing
I think that with intersectionWithKey, we are still holding to the
mathematical idea. Imagine I have a Map Hash List. When performing
intersection of two such maps, it can happen that for one hash there are
different values in the maps and so in the intersection the has is not
Generally if the Map k a is representing a set using both k and a,
the intersection on the same key can still be empty.
But this is not so in union -- if key is any of maps, it should be in
So personally I would generalize the combining function of
intersectionWith to (a -> b -> Maybe c),
but not generalize the combining function of unionWith, and instead
provide mergeWith with combining function (a -> a -> Maybe a).
(Similarly for *Key variants).
More information about the Libraries