[GHC] #7583: IO reordering

#7583: IO reordering ----------------------------------------+----------------------------------- Reporter: Heimdell | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.4.1 | Keywords: IO, invalid evaluation order Os: Linux | Architecture: x86_64 (amd64) Failure: Incorrect result at runtime | Blockedby: Blocking: | Related: ----------------------------------------+----------------------------------- I have a simple test program: {{{ main = do putStr "> " line <- getLine putStrLn line }}} In ghci, it writes "> " before receiving input: {{{ Prelude Main> main
WHAT WHAT }}}
But being compiled by ghc it writes "> " just after receiving input. {{{ maelstrom@ubuntu:~/vault$ ./test WHAT
WHAT }}}
That is not the behavior I expect. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7583 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7583: IO reordering ----------------------------------------+----------------------------------- Reporter: Heimdell | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.4.1 | Keywords: IO, invalid evaluation order Os: Linux | Architecture: x86_64 (amd64) Failure: Incorrect result at runtime | Blockedby: Blocking: | Related: ----------------------------------------+----------------------------------- Comment(by Yuras): The evaluation order is correct. It is related to line buffering on stdout. You should flush stdout after writing "> " and before reading input. In ghci the behavior is different probably cos it setup different buffering on stdout. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7583#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7583: IO reordering ---------------------------------------------+------------------------------ Reporter: Heimdell | Owner: Type: bug | Status: closed Priority: normal | Component: Compiler Version: 7.4.1 | Resolution: invalid Keywords: IO, invalid evaluation order | Os: Linux Architecture: x86_64 (amd64) | Failure: Incorrect result at runtime Blockedby: | Blocking: Related: | ---------------------------------------------+------------------------------ Changes (by monoidal): * status: new => closed * resolution: => invalid Comment: This is because GHC uses line buffering by default, while GHCi disables buffering. You can flush after each output or disable buffering: {{{ import System.IO main = do hSetBuffering stdout NoBuffering putStr "> " line <- getLine putStrLn line }}} -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7583#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC