
10 Jun
2011
10 Jun
'11
5:11 a.m.
forever a = a>> forever a
doesn't tie to itself without optimisations, so my guess is that it gets expanded when you run/eval/execState it in ghci, building the thunk
a>> a>> a>> a>> ...
If you define
forever' a = let a' = a>> a' in a'
the variant using forever' runs in constant space in ghci. This, like the explicit recursion, builds a cyclic structure, hence avoids the leak.
I see. It's difficult to reason about space complexity in presence of optimizer.