Simon Marlow | 4 Sep 2006 10:49
Picon

Re: putStr is not evaluated in the correct order

Tomasz Zielonka wrote:
> On Sat, Sep 02, 2006 at 05:11:33PM -0700, Jeremy Shaw wrote:
> 
>>GHCi and the compiled program do not buffer the output in quite the
>>same way.
> 
> 
> This comes up so often that perhaps GHCi should advertise those
> differences. For example, the starting message could say something
> like this:
> 
>    ___         ___ _
>   / _ \ /\  /\/ __(_)
>  / /_\// /_/ / /  | |      GHC Interactive, version 6.?, for Haskell 98.
> / /_\\/ __  / /___| |      http://www.haskell.org/ghc/
> \____/\/ /_/\____/|_|      Type :? for help.
> 
> For a list of differences between GHCi-interpreted and GHC-compiled
> programs, type :differences
> 
> Loading package base-1.0 ... linking ... done.

It is in the FAQ.  The FAQ is currently a bit hard to navigate and could do with 
splitting up into separate pages, though.

http://haskell.org/haskellwiki/GHC:FAQ#If_I_print_out_a_string_using_putStr.2C_and_then_attempt_to_read_some_input_using_hGetLine.2C_I_don.27t_see_the_output_from_the_putStr.

We could consider adding a message along the lines you suggest... any other ideas?

Cheers,
(Continue reading)

Bruno Martínez | 5 Sep 2006 19:58
Picon
Favicon

Re: putStr is not evaluated in the correct order

On Mon, 04 Sep 2006 05:49:08 -0300, Simon Marlow
<simonmarhaskell <at> gmail.com> wrote:

> It is in the FAQ.  The FAQ is currently a bit hard to navigate and could  
> do with splitting up into separate pages, though.
>
> http://haskell.org/haskellwiki/GHC:FAQ#If_I_print_out_a_string_using_putStr.2C_and_then_attempt_to_read_some_input_using_hGetLine.2C_I_don.27t_see_the_output_from_the_putStr.
>
> We could consider adding a message along the lines you suggest... any  
> other ideas?

C++ avoids this problem 'tieing' cin and cout.  Why can't haskell do the
same?

Bruno
David Sankel | 10 Sep 2006 04:34
Picon
Gravatar

Re: Re: putStr is not evaluated in the correct order

On 9/5/06, Bruno Martínez <br1 <at> internet.com.uy> wrote:

C++ avoids this problem 'tieing' cin and cout.  Why can't haskell do the
same?

I was thinking the same thing. I'm imagining a situation where processes are communicating to each other using pipes, but cannot think of a concrete case. Do you know if C++ has any way to disable tying std::cin and std::cout?

David
_______________________________________________
Haskell mailing list
Haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell
Bruno Martínez | 10 Sep 2006 20:10
Picon
Favicon

Re: Re: putStr is not evaluated in the correct order

On Sat, 09 Sep 2006 23:34:55 -0300, David Sankel <camior <at> gmail.com> wrote:

> On 9/5/06, Bruno Martínez <br1 <at> internet.com.uy> wrote:
>>
>> C++ avoids this problem 'tieing' cin and cout.  Why can't haskell do the
>> same?
>>
>
> I was thinking the same thing. I'm imagining a situation where processes  
> are communicating to each other using pipes, but cannot think of a  
> concrete
> case.

I don't see the problem.  According to "The C++ Programming Language" cout  
is flushed only when cin encounters an underflow, so it doesn't seem  
costly either.

> Do you know if C++ has any way to disable tying std::cin and
> std::cout?

Yes, cin.tie(NULL).

Bruno

     Conectese mas rapido y ahorre hasta un 50%
    Tel. 0909.2030 =>  $0,15 IVA incluido el minuto
______________________________________________________
http://www.internet.com.uy - En Uruguay somos internet
Clifford Beshers | 4 Sep 2006 21:27

Re: Re: putStr is not evaluated in the correct order


Simon Marlow wrote:
>
> We could consider adding a message along the lines you suggest... any 
> other ideas?
>

I remember running into this.  I wasn't confused by the expected 
behavior, it was the fact that ghci had different behavior than compiled 
programs and that the settings seem to be wrong at startup.  I tracked 
down this bug at the time and forgot to report it.

ghci starts with NoBuffering behavior, even though the mode appears to 
be LineBuffering.  Setting it once fixes the problem.

I've included a ghci session that demonstrates the bug by showing the 
change in behavior when pressing Control-D in response to each call to 
getLine. The results are identical for 6.4.1 and 6.6 rc1.

   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.4.1, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base-1.0 ... linking ... done.
Prelude> :m +System.IO
Prelude System.IO> hGetBuffering stdin >>= print
LineBuffering
Prelude System.IO> getLine >>= print
^D
"\EOT"
Prelude System.IO> hSetBuffering stdin NoBuffering >> hGetBuffering 
stdin >>= print
NoBuffering
Prelude System.IO> getLine >>= print
^D
"\EOT"
Prelude System.IO> hSetBuffering stdin LineBuffering >> hGetBuffering 
stdin >>= print
LineBuffering
Prelude System.IO> getLine >>= print
*** Exception: <stdin>: hGetLine: end of file
Prelude System.IO>

   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.5.20060831, for 
Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Prelude> :m +System.IO
Prelude System.IO> hGetBuffering stdin >>= print
LineBuffering
Prelude System.IO> getLine >>= print
^D
"\EOT"
Prelude System.IO> hSetBuffering stdin NoBuffering >> hGetBuffering 
stdin >>= print
NoBuffering
Prelude System.IO> getLine >>= print
^D
"\EOT"
Prelude System.IO> hSetBuffering stdin LineBuffering >> hGetBuffering 
stdin >>= print
LineBuffering
Prelude System.IO> getLine >>= print
*** Exception: <stdin>: hGetLine: end of file
Prelude System.IO>

Gmane