[Haskell-cafe] Plug space leak with seq. How?

Alexey Khudyakov alexey.skladnoy at gmail.com
Fri Jun 10 11:11:24 CEST 2011

> 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 

More information about the Haskell-Cafe mailing list