[email protected]
[Top] [All Lists]

[Haskell-cafe] Map unionWith generalization

Subject: [Haskell-cafe] Map unionWith generalization
From: Hans Aberg
Date: Wed, 27 Jan 2010 11:53:06 +0100
I need ideally some generalizations of unionWith and unionWithKey, for efficiency matters (i.e. avoiding conversions and traversing the maps more than once). I could use a modification of the code in Map.hs, but then the problem is that the module Map interface does not export the constructors of data Map. So suggestions are welcome.
For example, in Map String Integer (sparse representation of
monomials) compute the minimum value of all associative pairs with the
same key (the gcd); if only one key is present, the absent should be
treated as having value 0. So
  unionWith min xs ys
will not work, because unionWith will always apply the identity to the remaining value when one key is missing, whereas it should be sent to 0.
So here, one would want:
(a -> c) -> (b -> c) -> (a -> b -> c) -> Map k a -> Map k b -> Map k c where the two first functions are applied when the first or second key is missing.

Haskell-Cafe mailing list
[email protected]

<Prev in Thread] Current Thread [Next in Thread>