Re: [Haskell-cafe] Map unionWith generalization

2010-01-28 Thread Hans Aberg
On 28 Jan 2010, at 03:09, Twan van Laarhoven wrote: 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

[Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Hans Aberg
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

Re: [Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Jan-Willem Maessen
On Jan 27, 2010, at 5:53 AM, Hans Aberg wrote: 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

Re: [Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Hans Aberg
On 27 Jan 2010, at 14:56, Jan-Willem Maessen wrote: 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. Ah, the swiss army knife function on maps. This particular

Re: [Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Jan-Willem Maessen
On Jan 27, 2010, at 9:42 AM, Hans Aberg wrote: On 27 Jan 2010, at 14:56, Jan-Willem Maessen wrote: 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. Ah, the swiss

Re: [Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Hans Aberg
On 27 Jan 2010, at 16:33, Jan-Willem Maessen wrote: I'm not sure why you want to throw in functions between maps in the two first arguments. Then there is no requirement that single keys are preserved. But it is a good idea to have a Maybe so that one can remove keys on the fly. A good

Re: [Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Jan-Willem Maessen
On Jan 27, 2010, at 10:54 AM, Hans Aberg wrote: On 27 Jan 2010, at 16:33, Jan-Willem Maessen wrote: I'm not sure why you want to throw in functions between maps in the two first arguments. Then there is no requirement that single keys are preserved. But it is a good idea to have a

Re: [Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Hans Aberg
On 27 Jan 2010, at 21:29, Jan-Willem Maessen wrote: I'm thinking about (k - Maybe a - Maybe b - Maybe c) - Map k a - Map k b - Map k c The first two Maybe's tell if the keys are present, the last if one wants it in the resulting map. That has the same behavior semantically, but it's no more

Re: [Haskell-cafe] Map unionWith generalization

2010-01-27 Thread Twan van Laarhoven
Hans Aberg wrote: 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