-- not tail recursive sum1 1 = 1 sum1 x = x + sum1 (x - 1) -- should be tail recursive -- because of lazy evaluation, can still overflow the stack! -- ghc optimizations will alleviate this, but ghci won't sum2 x = let sum2' x accum = if x == 0 then accum else sum2' (x - 1) (accum + x) in sum2' x 0 main = putStr (show (sum2 1000000))