Minor containers API changes

Jan-Willem Maessen jmaessen at alum.mit.edu
Mon Nov 28 22:00:32 CET 2011


I strongly support all these changes (and agree with Milan's chocie of
options), having run into many of the inconsistencies in my own code
and had to write impedence matchers.

> 7) Improve the generality of intersectionWith.
>   Currently the Map and IntMap define
>     intersectionWith :: Ord k => (a -> b -> c) -> Map k a -> Map k b -> Map k c
>     intersectionWithKey :: Ord k => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c
>
>   But the combining function is not general enough. Consider two
>   IntMaps storing hashable elements as (hash(element), element).
>   When intersecting elements with the same hash, the intersection can
>   be empty.
>
>   I propose to change the type of these methods to
>     intersectionWith :: Ord k => (a -> b -> Maybe c) -> Map k a -> Map k b -> Map k c
>     intersectionWithKey :: Ord k => (k -> a -> b -> Maybe c) -> Map k a -> Map k b -> Map k c
>   (and appropriately for IntMap).
>
>   Note that the combining function of differenceWith already has type `(a -> b -> Maybe a)`.

The absence of intersection with this signature has been a particular annoyance.

-Jan-Willem Maessen



More information about the Libraries mailing list