
16 May
2007
16 May
'07
7:09 a.m.
How to solve task of reversing big list with constant heap space used? Amount of heap space used grows exponentially in following examples: 1: main = putStrLn.show.head $reverse [1..10000000] 2 (GHC): import Data.List main = putStrLn.show.head $foldl' (flip (:)) [] [1..10000000] 3 (GHC): import Control.Monad main = foldM (\x y -> return $ y:x) [] [1..10000000] >>= putStrLn.show.head -- Best regards, Sergey Perminov