[Haskell-cafe] Strange IO sequence behaviour (Was: sequence causing stack overflow on pretty small lists)
headprogrammingczar at gmail.com
Wed Sep 4 22:15:14 CEST 2013
Er, I seem to have misread and thought you were doing infinite replicateM,
so that explanation doesn't completely address your question. That's what I
get for reading on a phone!
On Sep 4, 2013 4:11 PM, "Joe Q" <headprogrammingczar at gmail.com> wrote:
> 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