[Haskell-cafe] hopefully, a very quick question about ByteString lib

Daniel Fischer daniel.is.fischer at web.de
Tue Oct 27 12:00:37 EDT 2009


Am Dienstag 27 Oktober 2009 16:47:12 schrieb Thomas DuBuisson:
> Iain,
> If you wanted to make sure it didn't have to do with ghci then you
> should have compiled the original code, not tested different
> functions.  The code you provided works fine compiled and I too am
> curious what is going on when you run it in ghci.
>
> Thomas

Look at the sources:

hGetLine :: Handle -> IO ByteString
#if !defined(__GLASGOW_HASKELL__)
hGetLine h = System.IO.hGetLine h >>= return . pack . P.map c2w
#else
hGetLine h = wantReadableHandle "Data.ByteString.hGetLine" h $ \ handle_ -> do
    case haBufferMode handle_ of
       NoBuffering -> error "no buffering"
       _other      -> hGetLineBuffered handle_

 where
  ...

So, in ghci, stdin isn't buffered and ByteString can't cope with that. Why exactly, I 
don't know.
Change code to

main = hSetBuffering stdin LineBuffering >> B.getLine >>= B.putStrLn

and it works.


More information about the Haskell-Cafe mailing list