[Haskell-cafe] unexpected compiler behavior
cgibbard at gmail.com
Tue Dec 5 06:13:58 EST 2006
The problem is most likely that line-buffered (or possibly
block-buffered) IO is turned on, which means that buffers will only
automatically be flushed to the display at the ends of lines. You can
fix it by importing System.IO, and either calling (hFlush stdout)
explicitly, or by calling (hSetBuffering NoBuffering stdout) at the
start of your program.
On 05/12/06, jepalomar23 at ono.com <jepalomar23 at ono.com> wrote:
> I am newbie in Haskell and do not understand why the interpreted mode
> differs from the compiled program.
> I run this code
> main = do
> putStr "line1"
> putStr "line2"
> return (x++y)
> either under runhugs or runghc or in a console under ghci and works
> properly, that is, first displays "line1" and then prompts for the
> corresponding inputs through the keyboard, and so on. However, if I
> compile the code with the command line
> ghc --make Main.hs -o main
> and launch the compiled program main, then at first prompts for the
> input lines through the keyboard and then displays the strings "line1"
> I have read in the tutorials that the command "do" implies an ordered
> execution and this only occurs in interpreted mode.
> Using the monadic notation >> , >>= occurs the same unordered behavior.
> ¿How can I avoid the unordered execution of this code in a compiled
> Thanks in advance.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe