Data.IntMap/IntSet inconsistencies

Ben midfield at gmail.com
Tue Nov 3 18:48:10 EST 2009


while we're on the topic, i'm curious as to why there isn't a zip /
join-type method for IntMaps / IntSets.  (i use the term join in
reference to SQL.)  i have defined some in the past like

-- maybe not efficient
joinOuterWithKey f m1 m2 d1 d2 =
    M.union (M.intersectionWithKey f m1 m2)
         $ M.union
               (M.mapWithKey f1 $ m1 M.\\ m2)
               (M.mapWithKey f2 $ m2 M.\\ m1)
    where f1 k l = f k l d2
          f2 k r = f k d1 r

-- left biased
joinLeftWithKey f m1 m2 d2 =
    M.union (M.intersectionWithKey f m1 m2) (M.mapWithKey f1 $ m1 M.\\ m2)
    where f1 k a = f k a d2

-- right biased
joinRightWithKey f m1 m2 d1 =
    M.union (M.intersectionWithKey f m1 m2) (M.mapWithKey f2 $ m2 M.\\ m1)
    where f2 k b = f k d1 b

joinInnerWithKey = M.intersectionWithKey

but

1) these are probably not terribly efficient, as they do multiple traversals

2) the types are not general enough : like zip you should be able to
take functions f : a->b->c instead of what intersectionWith forces you
to do (f: a->b->a).

the proper implementation should be easy, and trivially generalizes
intersectionWith and friends, i believe.

or am i missing something?

best, ben


More information about the Libraries mailing list