Brandon S. Allbery KF8NH wrote:
On 2008 May 13, at 17:01, Andrew Coppin wrote:
That definition of mean is wrong because it traverses the list twice.
(Curiosity: would traversing it twice in parallel work any better?)
As for the folds - I always *always* mix up
It might work "better" but you're still wasting a core that could be
put to better use doing something more sensible. It's pretty much
always best to do all the calculations that require traversing a given
list in a single traversal.
Yeah, you're probably right there. I mean, with sufficient inlining,
maybe you would end up with a loop that doesn't even construct any
heap-allocated list nodes, just adds up the integers as fast as it can
generate them.
On the other hand, N(N+1)/2N is probably even faster! ;-) So I guess
it's kinda of a daft example...
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe