[Haskell-cafe] GHC + interactive input/output

Philip Weaver philip.weaver at gmail.com
Fri Feb 8 19:41:37 EST 2008


Your "gsi> " is buffered because there's no newline at the end.  To flush
the buffer and force it to be printed immediately, use 'hFlush' from the
System.IO library, or use 'hSetBuffering' from that same library:
http://haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html

I believe you can observe the same behavior in C.

- Phil


On Feb 8, 2008 4:14 PM, Jonathan Cast <jonathanccast at fastmail.fm> wrote:

> $ cat > foo.c
> #include <stdio.h>
>
> int
> main()
> {
>   char s[1024];
>   printf("gsi> ");
>   gets(s);
>   printf("%s\n", s);
>   return 0;
> }
> $ make foo
> cc     gsi.c   -o gsi
> $ ./foo
> warning: this program uses gets(), which is unsafe.
> gsi> hello
> hello
> $ cat > foo.hs
> main = do
>   putStr "gsi> "
>   s <- getLine
>   putStrLn s
> $ ghc foo.hs -o foo
> $ ./foo
> hello
> gsi> hello
>
> (This is on MacOS X).  It strikes me that GHC is being
> extraordinarily unhelpful here.  Is there anyone on the planet who
> ever actually wants this behavior?
>
> jcc
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080208/17a9b850/attachment.htm


More information about the Haskell-Cafe mailing list