[Haskell-cafe] Strange IO sequence behaviour (Was: sequence causing stack overflow on pretty small lists)
headprogrammingczar at gmail.com
Wed Sep 4 22:11:47 CEST 2013
To give a very casual explanation, both mains are of the form "do this a
bunch of times and return the results". Your first is "do nothing and
return the ()s", but importantly, it has to execute all those nothings.
Your second is "print hello a bunch and return the ()s". The list it wants
to eventually return gets bigger and bigger as more prints happen, until
You should look at how replicateM works again, and hopefully it will make
more sense with that in mind.
On Sep 4, 2013 11:35 AM, "Tom Ellis" <
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:
> As an addendum to the recent discussion, can anyone explain why main
> quickly with a stack overflow, whereas main' is happy to print "Hi" for
> (eventually crashing due to an out of memory condition)?
> bignum = 100 * 1000 * 1000
> main = replicateM bignum (return ())
> main' = replicateM bignum (putStrLn "Hi")
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe