
People, I observe the output difference in running ./Bug and ./Bug >& log (under Linux) for the program import Dumatel main = do calcInput <- readFile "List0.inp" (putStr $ parseComputeShow calcInput) where parseComputeShow calcInput = concat ["t = ", showsn 3 t "\n", "tR = ", showsn 3 tR "\n"] where calc = addInput_default nilParseOpts (bool rpos) calcInput t = parse_default calc "parsing Term" "(a:nil) + (b:nil)" tR = evaluate emptyUMRMemo AllRules calc t -- I think, it can be reduced to much simpler one. The error break has to occur while computing tR. The difference is in printing or skipping of the result part before tR. The first command outputs --------------------------------- t = ((a : nil) + (b : nil)) Bug: substitute {(X, a), (Xs, nil), (Ys, (b : nil))} X: sort mismatch in substitution --------------------------------- And the second command skips (in ./log) the line of t = ... Who can tell what is the matter? How to have identic outputs in this example? Thank you in advance for explanation. ----------------- Serge Mechveliani mechvel@botik.ru

I'm just guessing, but it looks like a buffering problem.
When a program dies an abnormal death (like the "Bug:" thing probably
is) then the stdout buffer is not flushed and you'll miss that bit of
the output.
You could set stdout in NoBuffering mode and see if that helps.
-- Lennart
On Fri, Feb 20, 2009 at 9:38 AM, Serge D. Mechveliani
People, I observe the output difference in running ./Bug and ./Bug >& log (under Linux) for the program
import Dumatel main = do calcInput <- readFile "List0.inp" (putStr $ parseComputeShow calcInput) where parseComputeShow calcInput = concat ["t = ", showsn 3 t "\n", "tR = ", showsn 3 tR "\n"] where calc = addInput_default nilParseOpts (bool rpos) calcInput t = parse_default calc "parsing Term" "(a:nil) + (b:nil)" tR = evaluate emptyUMRMemo AllRules calc t
-- I think, it can be reduced to much simpler one. The error break has to occur while computing tR. The difference is in printing or skipping of the result part before tR. The first command outputs
--------------------------------- t = ((a : nil) + (b : nil)) Bug: substitute {(X, a), (Xs, nil), (Ys, (b : nil))} X: sort mismatch in substitution ---------------------------------
And the second command skips (in ./log) the line of t = ... Who can tell what is the matter? How to have identic outputs in this example?
Thank you in advance for explanation.
----------------- Serge Mechveliani mechvel@botik.ru
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On 2009 Feb 20, at 4:38, Serge D. Mechveliani wrote:
The first command outputs
--------------------------------- t = ((a : nil) + (b : nil)) Bug: substitute {(X, a), (Xs, nil), (Ys, (b : nil))} X: sort mismatch in substitution ---------------------------------
And the second command skips (in ./log) the line of t = ... Who can tell what is the matter?
The ghc runtime doesn't flush stdout when an exception stops the program. This is arguably a bug in the runtime; if you set stdout to line buffering or no buffering you should get pretty much the same output from both. (It's still possible for buffering to cause lines to come out in a different order, so you might prefer unbuffered). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Brandon S. Allbery KF8NH wrote:
On 2009 Feb 20, at 4:38, Serge D. Mechveliani wrote:
The first command outputs
--------------------------------- t = ((a : nil) + (b : nil)) Bug: substitute {(X, a), (Xs, nil), (Ys, (b : nil))} X: sort mismatch in substitution ---------------------------------
And the second command skips (in ./log) the line of t = ... Who can tell what is the matter?
The ghc runtime doesn't flush stdout when an exception stops the program. This is arguably a bug in the runtime; if you set stdout to line buffering or no buffering you should get pretty much the same output from both. (It's still possible for buffering to cause lines to come out in a different order, so you might prefer unbuffered).
stdout should be flushed when the program exits, regardless of whether it exits as a result of a clean exit or an exception. I've just checked the code, and that's certainly what is supposed to happen. If anyone has evidence to the contrary, please submit a bug report! Cheers, Simon

Simon Marlow
stdout should be flushed when the program exits, regardless of whether it exits as a result of a clean exit or an exception. I've just checked the code, and that's certainly what is supposed to happen. If anyone has evidence to the contrary, please submit a bug report!
I believe flushing of file handles on program exit is handled by finalizers attached to the handle. Until recently, ghc did not guarantee that any finalizer would ever run. Regards, Malcolm

Malcolm Wallace wrote:
Simon Marlow
wrote: stdout should be flushed when the program exits, regardless of whether it exits as a result of a clean exit or an exception. I've just checked the code, and that's certainly what is supposed to happen. If anyone has evidence to the contrary, please submit a bug report!
I believe flushing of file handles on program exit is handled by finalizers attached to the handle. Until recently, ghc did not guarantee that any finalizer would ever run.
Not exactly. There's a top-level exception handler that flushes stdout and stderr, so they always get flushed on exit (or at least, they are supposed to). Look in base:GHC.TopHandler for the code. Other handlers will only get flushed if their finalizers run, and nothing has changed here: we now guarantee execution of C finalizers, but that doesn't apply to the finalizers for Handles, which are Haskell code. Cheers, Simon
participants (5)
-
Brandon S. Allbery KF8NH
-
Lennart Augustsson
-
Malcolm Wallace
-
Serge D. Mechveliani
-
Simon Marlow