
On Tue, 2009-01-27 at 22:12 +0100, Henning Thielemann wrote:
$ ghc +RTS -M16m -c30 -RTS -e 'concat $ repeat "bla"'
This breaks down after a while, also if I increase the memory restriction:
... ablablablablablablablablablablablablablablablablablablablablablaHeap exhausted; Current maximum heap size is 15998976 bytes (15 Mb); use `+RTS -M<size>' to increase it.
Whereas this one works:
$ ghc +RTS -M16m -c30 -RTS -e 'cycle "bla"'
'concat' seems to be the culprit. What's so bad about it?
cycle builds a circular list: cycle xn = let ys = xn ++ ys in ys which concat isn't smart enough to do (obviously). That's not an issue normally, since the list is being consumed in a properly lazy fashion. But it looks like, for some reason, ghc -e is holding a pointer to the entire expression-to-evaluate in this case, so cons cells that have already been printed don't get garbage collected. To show that there's nothing wrong with concat per se, try this version instead: ghc +RTS -M16m -c30 -RTS -e 'print $ concat $ repeat "bla"' This should print forever without any problems. jcc