Proposal: more general unionWith for Data.Map

Christian Sattler sattler.christian at gmail.com
Tue Jan 24 20:42:03 CET 2012


2012/1/24 Johan Tibell <johan.tibell at gmail.com>
>
> On Tue, Jan 24, 2012 at 9:35 AM, Christian Sattler
> <sattler.christian at gmail.com> 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.
>
> Cheers,
> Johan

I don't care much about the naming, but note that the analogous
property already fails for the generalized intersectionWithKey in the
development version.



More information about the Libraries mailing list