intersectionSet, differenceSet

When using the new Data.Map.fromSet function I encountered that I use it many times in connection with Map.intersection and Map.difference like so Map.intersection m (Map.fromSet (const ()) s) Map.difference m (Map.fromSet (const ()) s) Actually the element types of the second operands of Map.intersection and Map.difference are completely independent and the values of these maps are not touched. Thus I think that intersection and difference with a Set are the more natural operation. How about adding Map.intersectionSet :: Ord k => Map k a -> Set k -> Map k a Map.differenceSet :: Ord k => Map k a -> Set k -> Map k a to Data.Map?

Sounds ok, by why especially for Set. Why not (also) Map.intersectionList :: Ord k => Map k a -> [k] -> Map k a Map.differenceList :: Ord k => Map k a -> [k] -> Map k a ? Screams for a generalization. On 15.11.12 11:34 AM, Henning Thielemann wrote:
When using the new Data.Map.fromSet function I encountered that I use it many times in connection with Map.intersection and Map.difference like so
Map.intersection m (Map.fromSet (const ()) s) Map.difference m (Map.fromSet (const ()) s)
Actually the element types of the second operands of Map.intersection and Map.difference are completely independent and the values of these maps are not touched. Thus I think that intersection and difference with a Set are the more natural operation. How about adding
Map.intersectionSet :: Ord k => Map k a -> Set k -> Map k a Map.differenceSet :: Ord k => Map k a -> Set k -> Map k a
to Data.Map?
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Andreas Abel <>< Du bist der geliebte Mensch. Theoretical Computer Science, University of Munich Oettingenstr. 67, D-80538 Munich, GERMANY andreas.abel@ifi.lmu.de http://www2.tcs.ifi.lmu.de/~abel/

On Thu, 15 Nov 2012, Andreas Abel wrote:
Sounds ok, by why especially for Set. Why not (also)
Map.intersectionList :: Ord k => Map k a -> [k] -> Map k a Map.differenceList :: Ord k => Map k a -> [k] -> Map k a
? Screams for a generalization.
I assume that Map.differenceSet can make use of the internal tree structure of a set and is thus more efficient. The documentation of Map.difference says it uses an adaption of hedge-union and this could also be used for Map.differenceSet.

On Thu, 15 Nov 2012, Andreas Abel wrote:
Sounds ok, by why especially for Set. Why not (also)
Map.intersectionList :: Ord k => Map k a -> [k] -> Map k a Map.differenceList :: Ord k => Map k a -> [k] -> Map k a
? Screams for a generalization.
I assume that Map.differenceSet can make use of the internal tree structure of a set and is thus more efficient. The documentation of Map.difference says it uses an adaption of hedge-union and this could also be used for Map.differenceSet.
This is true for Map and Set, although the difference versus Map.insersection m (fromSet (const ()) s) will be probably minor. It is not the case for IntMap and IntSet, as these has different representation. Cheers, Milan
participants (3)
-
Andreas Abel
-
Henning Thielemann
-
Milan Straka