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.

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to