
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. John [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. On Tue, Aug 27, 2013 at 9:19 PM, John Alfred Nathanael Chee < cheecheeo@gmail.com> wrote:
This is somewhat related: http://ghc.haskell.org/trac/ghc/ticket/4219
This also solves the concrete problem you gave in your original post (in reverse order):
import Control.Monad import System.Random
sequencel :: Monad m => [m a] -> m [a] sequencel = foldM (\tail m -> (\x -> return $ x : tail) =<< m) []
main :: IO () main = print =<< sequencel (replicate 1000000 (randomIO :: IO Integer))
Following on Reid's point, maybe it's worth noting in the documentation that replicateM, mapM, and sequence are not tail recursive for Monads that define (>>=) as strict in the first argument?
On 27/08/13 20:37, Patrick Palka wrote:
You can use ContT to force the function to use heap instead of stack space, e.g. runContT (replicateM 1000000 (lift randomIO)) return
That is interesting, and works.
Unfortunately its pure existence will not fix sequence, mapM etc. in
On Tue, Aug 27, 2013 at 6:07 AM, Niklas Hambüchen
wrote: base. _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Love in Jesus Christ, John Alfred Nathanael Chee http://www.biblegateway.com/ http://web.cecs.pdx.edu/~chee/
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries