
I
On 1 February 2010 11:54, Gabi
Hi Stephen, Thanks for the answer. Now I got confused :)
1. What is seq used for if it doesn't force strictness ? 2. Why the accumulator is important ? In other words why the following is much slower ? Isn't it RT too ?
slowSum :: [Integer] -> Integer slowSum[] = 0 slowSum (x:xs) = x `seq` x + slowSum xs
Hi Gabi It seems to be classified as 'almost tail recursion', see here: http://www.haskell.org/haskellwiki/Performance/Accumulating_parameter In slowSum although x gets 'forced' it still has to be added to the result of the recursive call [ slowSum xs ], so there isn't much that can actually be done with it at each recursive step until you get an answer back (what it actually does is build up the notorious [x + ..] thunks). Best wishes Stephen