15 Feb
2005
15 Feb
'05
4:45 p.m.
Hello, 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 following program: 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. *Main> test 3 *Main> testT *** Exception: stack overflow *Main> Could someone please explain this to me? / Emil