Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-27 Thread Peter Verswyvelen
Well, this approach has the problem that the running sum of key k blocks until a new value for that k arrives in the input stream. If you wanted to know the sum of the values of each key after you got nelements in the input stream, we could change the valuesWithKey inner function into:

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-27 Thread jean-christophe mincke
Hello What do you think of this? There is perhaps a recursive call that should be made tail recursive but it seems to work. The 'group' function takes the list of pairs as input and outputs a list of maps from key to sums. The nth element of the list of maps corresponds to the grouping applied

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-26 Thread Peter Verswyvelen
I'm also learning Haskell so the solution below might be (1) inefficient and (2) incorrect, but hey, let's give it a try :-) For simplicity, in the testing code, I assume an infinite list of key/value pairs where they keys are of type Char between 'a' and 'z' and the values are Integers (the code

[Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Gü?nther Schmidt
Hi, let say I got an unordered lazy list of key/value pairs like [('a', 99), ('x', 42), ('a', 33) ... ] and I need to sum up all the values with the same keys. So far I wrote a naive implementation, using Data.Map, foldl and insertWith. The result of this grouping operation, which is

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Luke Palmer
On Tue, Mar 24, 2009 at 3:15 PM, Gü?nther Schmidt gue.schm...@web.dewrote: Hi, let say I got an unordered lazy list of key/value pairs like [('a', 99), ('x', 42), ('a', 33) ... ] and I need to sum up all the values with the same keys. So far I wrote a naive implementation, using

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Luke Palmer
On Tue, Mar 24, 2009 at 3:51 PM, Luke Palmer lrpal...@gmail.com wrote: On Tue, Mar 24, 2009 at 3:15 PM, Gü?nther Schmidt gue.schm...@web.dewrote: Hi, let say I got an unordered lazy list of key/value pairs like [('a', 99), ('x', 42), ('a', 33) ... ] and I need to sum up all the values

Re: [Haskell-cafe] Grouping - Map / Reduce

2009-03-24 Thread Ketil Malde
Gü?nther Schmidt gue.schm...@web.de writes: let say I got an unordered lazy list of key/value pairs like [('a', 99), ('x', 42), ('a', 33) ... ] and I need to sum up all the values with the same keys. So far I wrote a naive implementation, using Data.Map, foldl and insertWith.