[Haskell-cafe] unexpected compiler behavior

Cale Gibbard 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:
> Hi,
> 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"
>           x<-getLine
>           putStr "line2"
>           y<-getLine
>           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"
> "line2".
> 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
> program?
> Thanks in advance.
> jepalomar
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list