Proposal: more general unionWith for Data.Map

Johan Tibell johan.tibell at
Tue Jan 24 20:25:50 CET 2012

On Tue, Jan 24, 2012 at 9:35 AM, Christian Sattler
<sattler.christian at> wrote:
> There are some high-level operations on maps which take two tree traversals
> only because the interface fails to expose sufficiently general functions.
> This proposal is concerned with an analogue of unionWithKey of type Ord k =>
> (k -> a -> a -> Maybe a) -> Map k a -> Map k a -> Map k a, with the intended
> semantics that if a key is present in both maps and the operation applied to
> the key and corresponding values returns Nothing, the key is deleted from
> the result.

Is union really an appropriate name here? I expect the following to hold:

forall k ∊ (keys m1) ∪ (keys m2) => k ∊ (m1 ∪ m2)

This means that keys must not be deleted by the union operator.
Perhaps 'merge' is a better name.


More information about the Libraries mailing list