On Wed, May 14, 2008 at 06:08:28PM +0100, Paul Johnson wrote:
We've had a big debate over
mean xs = foldl' (+) 0 xs / fromIntegral (length xs)
For anyone who didn't follow it, the problem is that mean needs to
traverse its argument twice, so the entire list has to be held in
memory.
Don Stewart wrote:
You'd want a general fusion framework for this...
Stream fusion... at least does this for zips...
but for an arbitrary 'f' instead of zip,
seems harder.
And of course, you wouldn't want that:
f xs = xs : map expensiveCalculation xs
Please don't fuse those two loops into
Yitzchak Gale wrote:
And of course, you wouldn't want that:
f xs = xs : map expensiveCalculation xs
Please don't fuse those two loops into one.
...doesn't type check. Did you mean (++)?
In the case of mean, the outer function in question
is /, and that is a good candidate for fusion
On Thu, May 15, 2008 at 8:45 PM, Andrew Coppin
[EMAIL PROTECTED] wrote:
Yitzchak Gale wrote:
And of course, you wouldn't want that:
f xs = xs : map expensiveCalculation xs
Please don't fuse those two loops into one.
...doesn't type check. Did you mean (++)?
Hmm? While the name might
We've had a big debate over
mean xs = foldl' (+) 0 xs / fromIntegral (length xs)
For anyone who didn't follow it, the problem is that mean needs to
traverse its argument twice, so the entire list has to be held in
memory. So if xs = [1..10] then mean xs uses all your
memory, but
Paul Johnson wrote:
The solution is for the programmer to rewrite mean to accumulate a
pair containing the running total and count together, then do the
division. This makes me wonder: could there be a compiler optimisation
rule for this, collapsing two iterations over a list into one.
Do
Albert Y. C. Lai wrote:
If you worry that the sum thread and the length thread are not
synchronized and therefore there is still no bound on the list prefix
kept in memory, I'm sure you can improve it by one of the chunking
strategies.
I'm more worried that data now has to go through tiny