[Haskell] Writer monad
emax at cs.chalmers.se
Tue Feb 15 11:45:26 EST 2005
I have a huge space leak in a program due to laziness in the writer monad. Now
when I'm trying to examine the behaviour of writer I get a bit puzzled by the
foo :: MonadWriter [Int] m => Int -> m ()
foo n = do tell [n]
foo $ n+1
test = (snd $ runWriter $ foo 0) !! 3
testT = (snd $ runIdentity $ runWriterT $ foo 0) !! 3
I would expect both test and testT to terminate with the value 3, due to the
laziness that caused me problems. But here is the actual run results:
Ok, modules loaded: Main.
*** Exception: stack overflow
Could someone please explain this to me?
More information about the Haskell