In an idle moment I wrote the attached program, which prints the song "1 man went to mow". However if I try it on Hugs (version of March 1999, running on a Sparc station with 128MB), it is unable to print more than about 91 verses, after which it prints ERROR: Garbage collection fails to reclaim sufficient space OK, so I suppose the reason is Hugs doesn't do tail recursion elimination, though giving up on a total stack depth of less than 200 seems a bit pathetic. But what does surprise me is that after I've had that ERROR, I can't do anything. If I try (say) Main> verse 10 Hugs bombs out after only a few lines with the same ERROR. Why doesn't it collect all the space it used in the previous step? Is there a space leak somewhere?
nmen 1 = putStr "1 man" nmen n = putStr(show n) >> putStr " men" mendown n = nmen n >> if n==1 then putStr " and his dog\n(Woof!)\n" else putStr ",\n" >> mendown (n-1) wtm = putStr "went to mow" wtman = wtm >> putStr " a meadow.\n" verse n = (nmen n) >> putStr " " >> wtm >> putStr ",\n" >> wtman >> mendown n >> wtman >> putStr "\n" mow n = verse n >> mow(n+1) main = (mow 1) :: IO ()
