Proposal: more general unionWith for Data.Map
wren ng thornton
wren at freegeek.org
Fri Jan 27 03:27:22 CET 2012
On 1/24/12 3:39 PM, Milan Straka wrote:
> Hi,
>
>>> On Tue, Jan 24, 2012 at 11:42 AM, Christian Sattler
>>> <sattler.christian at gmail.com> wrote:
>>>> I don't care much about the naming, but note that the analogous
>>>> property already fails for the generalized intersectionWithKey in the
>>>> development version.
>>>
>>> I suspected as much. I think the current intersectionWithKey is
>>> broken. We should have a single function, mergeWithKey, that allows
>>> people to do the things they currently do using Maybe return values in
>>> e.g. intersectionWithKey.
>>
>> Funnily, I just also used mergeWithKey for the "ultimate combining
>> function" in this thread :)
>>
>> FYI, the new intersectionWithKey is not released yet -- maybe we could
>> leave intersectionWithKey as it is, and provide mergeWith[Key] instead.
>> Opinions?
>
> Oh, Christian just noted that the performance of
> mergeWithKey :: Ord k => (k -> Maybe a -> Maybe b -> Maybe c) -> Map k a -> Map k b -> Map k c
If you're going to go for that level of generality, I'd suggest looking
into my currently unpublished Data.Or[1] for combining the a and b
arguments with the correct semantics. Naturally, this function will be
less efficient for union-like operators since it requires traversing
non-intersecting branches of the trees as well.
[1] http://code.haskell.org/~wren/data-or/dist/doc/html/data-or/
--
Live well,
~wren
More information about the Libraries
mailing list