
9 Jun
2011
9 Jun
'11
12:41 p.m.
On 09.06.2011 20:09, Yves Parès wrote:
Is it not:
noLeak :: State Int () noLeak = do a <- get *>* *let a' = (a + 1) a' `seq` put a'* noLeak
??
Indeed. Now I understand. It didn't work for me earlier because of different behavior of 'forever' in ghci and compiled code. This function leaks in ghci and do not in compiled code without optimizations (with optimizations GHC is smart enough to make everything strict).
noLeak = forever $ do { a <- get; let a' = a+1; a' `seq` put a' }
Function with explicit recursion do not leak in both cases.
noLeak = do { a <- get; let a' = a+1; a' `seq` put a'; noLeak }
What causes this difference?