[Haskell-cafe] flushing trace debug output before getting other output

Terrence Brannon bauhaus at metaperl.com
Sun Jul 17 00:46:30 EDT 2005

I'm working on exercise 6.16 in Thompson's "Haskell; the Craft of
Functional Programming"

My goal for the moment is to call printPicture to see my results:

type Picture = [[Char]]
printPicture :: Picture -> IO ()
printPicture = putStr . concat . map (++"\n")

And everything is encouraging. The return type of my function syncs

*Main> :t superimposeImage imgA imgB
superimposeImage imgA imgB :: [[Char]]

Now, the only issue is that I have put a number of trace statements in
my program whose output is *interspersed* with the return data. The
return data is simply lists of characters, where each character is "."
or "#"

*Main> printPicture $ superimposeImage imgA imgB
siPointLogic i1 i2 0 15
.siPointLogic i1 i2 1 15
.siPointLogic i1 i2 2 15
.siPointLogic i1 i2 3 15
.siPointLogic i1 i2 4 15
.siPointLogic i1 i2 5 15
.siPointLogic i1 i2 6 15
.siPointLogic i1 i2 7 15
.siPointLogic i1 i2 8 15
.siPointLogic i1 i2 9 15
.siPointLogic i1 i2 10 15
.siPointLogic i1 i2 11 15

When I remove my various trace statements, I get what I want:

*Main> printPicture $ superimposeImage imgA imgB

So the question is, how can I leave the trace statements in the code
and yet get the printPicture output after all the debugging output has

It only makes sense for it to work that way. The trace output
occurs during the program and in particular, during the program
*prior* to the call to printPicture. Therefore all of the trace output
should have finished *prior* to printPicture outputting it's rows.

	Carter's Compass: I know I'm on the right track when,
	   by deleting something, I'm adding functionality.

More information about the Haskell-Cafe mailing list