Bulat Ziganshin wrote:
Hello Thomas,

Thursday, October 23, 2008, 8:41:04 PM, you wrote:

The problem is not fitting a 10^8 element list in memory, the
following works fine
 (when compiled, though not in ghci):
t = putStrLn . show . last $ [1..10^8::Int]

this runs in 1k space, thanks to lazy evaluation. 10^8-length list
needs ~3gb of memory, it was discussed just a few days ago

To elaborate, t does this: compute the next item in the list, throw the previous item away, until there is no next item, now we have something to print. We never keep the whole list.

But this may keep the whole list:

u = (putStrLn . show . last $ list) >> (putStrLn . show . head $ list)
  where list = [1..10^8::Int]

Have fun!
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to