Proposal: more general unionWith for Data.Map

Henning Thielemann schlepptop at henning-thielemann.de
Tue Jan 24 20:35:41 CET 2012


Johan Tibell schrieb:
> 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.

Sounds better than my 'unionUpdate'.





More information about the Libraries mailing list