<div dir="ltr"><div><div>IMHO it's perfectly reasonable to expect sequence/replicateM/mapM to be able to handle a list of ~1e6 elements in the Unescapable Monad (i.e. IO). All the alternate implementations in the world won't be as handy as Prelude.sequence, and no amount of documentation will prevent people from running into this headlong*. So unless there's a downside to upping the stack size limitation I'm unaware of, +1 to that suggestion from me.<br>
<br></div><div>John<br></div><div>[1] Most people are physically incapable of reading documents that explain why what they want to do won't work. Even if people did read the documentation, I suspect that the people most in need of the information would be the least likely to understand how it applies to their situation.<br>
</div></div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 27, 2013 at 9:19 PM, John Alfred Nathanael Chee <span dir="ltr"><<a href="mailto:cheecheeo@gmail.com" target="_blank">cheecheeo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is somewhat related: <a href="http://ghc.haskell.org/trac/ghc/ticket/4219" target="_blank">http://ghc.haskell.org/trac/ghc/ticket/4219</a><br>
<br>
This also solves the concrete problem you gave in your original post<br>
(in reverse order):<br>
<br>
import Control.Monad<br>
import System.Random<br>
<br>
sequencel :: Monad m => [m a] -> m [a]<br>
sequencel = foldM (\tail m -> (\x -> return $ x : tail) =<< m) []<br>
<br>
main :: IO ()<br>
main = print =<< sequencel (replicate 1000000 (randomIO :: IO Integer))<br>
<br>
Following on Reid's point, maybe it's worth noting in the<br>
documentation that replicateM, mapM, and sequence are not tail<br>
recursive for Monads that define (>>=) as strict in the first<br>
argument?<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Aug 27, 2013 at 6:07 AM, Niklas Hambüchen <<a href="mailto:mail@nh2.me">mail@nh2.me</a>> wrote:<br>
> On 27/08/13 20:37, Patrick Palka wrote:<br>
>> You can use ContT to force the function to use heap instead of stack<br>
>> space, e.g. runContT (replicateM 1000000 (lift randomIO)) return<br>
><br>
> That is interesting, and works.<br>
><br>
> Unfortunately its pure existence will not fix sequence, mapM etc. in base.<br>
><br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Love in Jesus Christ, John Alfred Nathanael Chee<br>
<a href="http://www.biblegateway.com/" target="_blank">http://www.biblegateway.com/</a><br>
<a href="http://web.cecs.pdx.edu/~chee/" target="_blank">http://web.cecs.pdx.edu/~chee/</a><br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</div></div></blockquote></div><br></div>