[Haskell-cafe] Strange IO sequence behaviour (Was: sequence causing stack overflow on pretty small lists)

Joe Q 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
poof!

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
> crashes
> quickly with a stack overflow, whereas main' is happy to print "Hi" for
> ages
> (eventually crashing due to an out of memory condition)?
>
>     bignum = 100 * 1000 * 1000
>     main   = replicateM bignum (return ())
>     main'  = replicateM bignum (putStrLn "Hi")
>
> Tom
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130904/b6a25b03/attachment.htm>


More information about the Haskell-Cafe mailing list