RE: Histogram-building code (was: Re: Yet another weakly defined bug report)

One question though, about hFlush. I print out the status by repeatedly putStr'ing "blah blah \r". With NoBuffering set, it works, but when following the putStr with 'hFlush stdout', it doesn't (only outputs very sporadically. I guess I'm misunderstanding the function of hFlush, anybody care to elaborate?)
It could be a bug. Can you provide us with a cut-down example? Cheers, Simon

Hi, I have a program, structured approximately like so main = do let stage1 = e1... let stage2 = e2...stage1... stage3 <- e3...stage2 case something of foo -> output stage1 bar -> output stage2 baz -> output stage3 I think this is an improvement from using multiple main functions, since it reveals the pipeline structure of the program and the modularity of the stages. It appears¹, however, that naming the result of stage1 prevents it from being garbage collected when subsequent stages are produced. Since stage1 is a huge list, this leads to a space leak. So, is there any way to avoid this? Do I need to restructure my program? I could conceivably do main = do let stage1 = e1... let stage2 = e2...(e1...)... : and so on, but an aggressive (but slightly dumb) compiler might rediscover the similarity and CSE it. Suggestions more than welcome. -kzm ¹ Memory retainer profiling shows the product being retained by SYSTEM, so I *think* this is the right interpretation. -- If I haven't seen further, it is by standing in the footprints of giants

Ketil Z. Malde writes:
I have a program, structured approximately like so
main = do let stage1 = e1... let stage2 = e2...stage1... stage3 <- e3...stage2 case something of foo -> output stage1 bar -> output stage2 baz -> output stage3 [..] It appears¹, however, that naming the result of stage1 prevents it from being garbage collected when subsequent stages are produced. Since stage1 is a huge list, this leads to a space leak.
What is "something"? Is it a literal constructor (Foo, Bar, or Baz), or something computed elsewhere, or something taken from the command line? If it's a literal constructor, GHC can optimise the case away; in the other cases, it can't know until runtime which will be used. If "something" depends on stage3, then stage1 and stage2 *must* be held onto until the end. --KW 8-) --KW 8-)
participants (3)
-
Keith Wansbrough
-
ketil@ii.uib.no
-
Simon Marlow