<div dir="ltr"><div><div>IMHO it&#39;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&#39;t be as handy as Prelude.sequence, and no amount of documentation will prevent people from running into this headlong*.  So unless there&#39;s a downside to upping the stack size limitation I&#39;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&#39;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">&lt;<a href="mailto:cheecheeo@gmail.com" target="_blank">cheecheeo@gmail.com</a>&gt;</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 =&gt; [m a] -&gt; m [a]<br>
sequencel = foldM (\tail m -&gt; (\x -&gt; return $ x : tail) =&lt;&lt; m) []<br>
<br>
main :: IO ()<br>
main = print =&lt;&lt; sequencel (replicate 1000000 (randomIO :: IO Integer))<br>
<br>
Following on Reid&#39;s point, maybe it&#39;s worth noting in the<br>
documentation that replicateM, mapM, and sequence are not tail<br>
recursive for Monads that define (&gt;&gt;=) 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 &lt;<a href="mailto:mail@nh2.me">mail@nh2.me</a>&gt; wrote:<br>
&gt; On 27/08/13 20:37, Patrick Palka wrote:<br>
&gt;&gt; You can use ContT to force the function to use heap instead of stack<br>
&gt;&gt; space, e.g. runContT (replicateM 1000000 (lift randomIO)) return<br>
&gt;<br>
&gt; That is interesting, and works.<br>
&gt;<br>
&gt; Unfortunately its pure existence will not fix sequence, mapM etc. in base.<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Libraries mailing list<br>
&gt; <a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
&gt; <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>