[Haskell-cafe] stack overflow pain

2011-09-21 Thread Tim Docker
I'm getting a stack overflow exception in code like this: -- applyAction :: A - IO [B] vs - fmap concat $ mapM applyAction sas return vs I don't get it if I change the code to this: -- applyAction :: A - IO [B] mapM_

Re: [Haskell-cafe] stack overflow pain

2011-09-21 Thread Heinrich Apfelmus
Tim Docker wrote: I'm getting a stack overflow exception in code like this: -- applyAction :: A - IO [B] vs - fmap concat $ mapM applyAction sas return vs I don't get it if I change the code to this: -- applyAction :: A - IO [B]

Re: [Haskell-cafe] stack overflow pain

2011-09-21 Thread Tim Docker
On 21/09/11 02:39, Heinrich Apfelmus wrote: Tim Docker wrote: I'm getting a stack overflow exception in code like this: -- applyAction :: A - IO [B] vs - fmap concat $ mapM applyAction sas return vs I don't get it if I change the code to this: --

Re: [Haskell-cafe] stack overflow pain

2011-09-21 Thread Daniel Fischer
On Thursday 22 September 2011, 01:00:37, Tim Docker wrote: I believe the error is happening in the concat because there are subsequent IO actions that fail to execute. ie the code is equivalent to: vs - fmap concat $ mapM applyAction sas someOtherAction consume

Re: [Haskell-cafe] stack overflow pain

2011-09-21 Thread Leon Smith
On Wed, Sep 21, 2011 at 3:39 AM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Of course, a list of 1 million items is going to take a lot of memory, unless you generate it lazily. Unfortunately  mapM  cannot generate its result lazily because it has to execute all IO actions before

Re: [Haskell-cafe] stack overflow pain

2011-09-21 Thread Ketil Malde
Tim Docker t...@dockerz.net writes: mapM_ applyAction sas Maybe you could try a lazy version of mapM? E.g., I think this would do it: import System.IO.Unsafe (unsafeInterleaveIO) : mapM' f = sequence' . map f where sequence' ms = foldr k (return []) ms k m m' =

Re: [Haskell-cafe] stack overflow pain

2011-09-21 Thread Felipe Almeida Lessa
On Wed, Sep 21, 2011 at 6:04 AM, Ketil Malde ke...@malde.org wrote: Tim Docker t...@dockerz.net writes:         mapM_ applyAction sas Maybe you could try a lazy version of mapM?  E.g., I think this would do it: Another option is to use a version of mapM that accumulates the result on the

Re: [Haskell-cafe] stack overflow pain

2011-09-21 Thread Bas van Dijk
On 21 September 2011 17:32, Felipe Almeida Lessa felipe.le...@gmail.com wrote: On Wed, Sep 21, 2011 at 6:04 AM, Ketil Malde ke...@malde.org wrote: Tim Docker t...@dockerz.net writes:         mapM_ applyAction sas Maybe you could try a lazy version of mapM?  E.g., I think this would do it: