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" <headprogrammingc...@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 > 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-2...@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@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe