[Haskell-cafe] mapM is supralinear?
daniel.is.fischer at googlemail.com
Fri Sep 9 02:17:29 CEST 2011
On Friday 09 September 2011, 00:41:11, Roman Cheplyaka wrote:
> * Ertugrul Soeylemez <es at ertes.de> [2011-09-07 16:20:03+0200]
> > In general it's a bad idea to use mapM over IO.
> Could you explain why?
Take it with a grain of salt, there's nothing necessarily wrong with using
mapM over IO on short lists.
The problem is that IO's semantics imply that nothing can be made available
before the entire list has been consumed and a large thunk is built on the
way. Thus for longish lists there's a serious risk of stack overflows (or
even heap exhaustion if you mapM the right [wrong] functions).
The same applies to replicateM, and to other monads with a (>>=) which
isn't lazy enough.
More information about the Haskell-Cafe