Re: [Haskell-cafe] Finding the average in constant space
Sorry for the delayed response -- I've had exams the past few days. On Sun, May 27, 2012 at 8:21 PM, Eugene Kirpichov ekirpic...@gmail.com wrote: A lot of people have done this :) eg from me: google up a fairly recent thread from me about processing streams and perhaps the keyword timeplot (writing from a dying phone, can't do myself) If you mean this: http://www.haskell.org/pipermail/haskell-cafe/2011-December/097908.html and this: https://github.com/jkff/timeplot/blob/master/Tools/TimePlot/Incremental.hs then you're right -- the types match up exactly! The funny thing is, I remember seeing that message half a year ago and having absolutely no idea what any of it meant. Now I've actually tried it myself, reifying the case expression actually makes perfect sense. On Sun, May 27, 2012 at 11:43 PM, Stephen Tetley stephen.tet...@gmail.com wrote: There are a few blog posts by Conal Elliott and Max Rabkin (I think) reifying folds as a data type to get more composition and thus fold different functions at the same time. Search for beautiful folding with the above authors names. Personally I didn't find the examples significantly more beautiful that using regular composition in a normal fold - only that that the helper functions to manage pairs aren't in the standard library. This was already bookmarked, funnily enough: http://squing.blogspot.co.nz/2008/11/beautiful-folding.html I don't think that solution was particularly beautiful either. It seems a bit over-the-top, hiding the state in an existential type when a simple closure would do. However, I don't understand what you mean by regular composition in a normal fold. Wait, what's an irregular composition? Abnormal fold? ;) On Mon, May 28, 2012 at 7:33 AM, Steffen Schuldenzucker sschuldenzuc...@uni-bonn.de wrote: This is (a special case of) the main point in the design of iteratees. See e.g. the definition of the 'Iteratee' type in the enumeratee library. - Looks pretty much like your 'Fold' type with an additional state (done or not yet done). Also, the pipe package seems to provide something similar. I haven't looked too much into iteratees until now, but in hindsight it seems obvious why they're implemented that way -- they have to iterate over a stream chunk by chunk, keeping state as they go along, just like the Fold type. Thanks for pointing that out! Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Finding the average in constant space
Hello all I just came up with a way of executing multiple folds in a single pass. In short, we can write code like this: average = foldLeft $ (/) $ sumF * lengthF and it will only traverse the input list once. The code is at: https://gist.github.com/2802644 My question is: has anyone done this already? If not, I might release this on Hackage -- it seems quite useful. Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Finding the average in constant space
A lot of people have done this :) eg from me: google up a fairly recent thread from me about processing streams and perhaps the keyword timeplot (writing from a dying phone, can't do myself) 27.05.2012, в 12:04, Chris Wong chrisyco+haskell-c...@gmail.com написал(а): Hello all I just came up with a way of executing multiple folds in a single pass. In short, we can write code like this: average = foldLeft $ (/) $ sumF * lengthF and it will only traverse the input list once. The code is at: https://gist.github.com/2802644 My question is: has anyone done this already? If not, I might release this on Hackage -- it seems quite useful. Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Finding the average in constant space
There are a few blog posts by Conal Elliott and Max Rabkin (I think) reifying folds as a data type to get more composition and thus fold different functions at the same time. Search for beautiful folding with the above authors names. Personally I didn't find the examples significantly more beautiful that using regular composition in a normal fold - only that that the helper functions to manage pairs aren't in the standard library. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Finding the average in constant space
Hi Chris, On 05/27/2012 10:04 AM, Chris Wong wrote: I just came up with a way of executing multiple folds in a single pass. In short, we can write code like this: average = foldLeft $ (/)$ sumF* lengthF and it will only traverse the input list once. The code is at: https://gist.github.com/2802644 My question is: has anyone done this already? If not, I might release this on Hackage -- it seems quite useful. This is (a special case of) the main point in the design of iteratees. See e.g. the definition of the 'Iteratee' type in the enumeratee library. - Looks pretty much like your 'Fold' type with an additional state (done or not yet done). Also, the pipe package seems to provide something similar. -- Steffen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe