[Haskell-cafe] stack overflow pain
Tim Docker
tim at dockerz.net
Thu Sep 22 00:17:09 CEST 2011
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_ applyAction sas
return []
But of course, I need the results from the actions. I know that
the returned list contains approximately 1 million items.
Any suggestions on how I should rewrite the first code snippet
to not blow the stack?
I do find debugging stack overflow errors quite difficult - with little
information from the runtime I'm often left guessing which parts of
a large codebase might be causing them.
Note that there's plenty of heap space available, it's the evaluation
stack that is being used up. I could run with -K to increase the size
of the stack, but if possible I'd rather solve this in the code.
Thanks for any pointers.
Tim
More information about the Haskell-Cafe
mailing list