views:

144

answers:

2

I've tried this:

main = do
    hSetBuffering stdin NoBuffering 
    c <- getChar

but it waits until the enter is pressed, which is not what I want. I want to read the character immediately after user presses it.

I am using ghc v6.12.1 on Windows 7.

EDIT: workaround for me was moving from GHC to WinHugs, which supports this correctly.

+7  A: 

Might be a bug:

http://hackage.haskell.org/trac/ghc/ticket/2189

Artelius
+4  A: 

Hmm.. Actually I can't see this feature to be a bug. When you read stdin that means that you want to work with a "file" and when you turn of buffering you are saying that there is no need for read buffer. But that doesn't mean that application which is emulating that "file" should not use write buffer. For linux if your terminal is in "icanon" mode it doesn't send any input until some special event will occur (like Enter pressed or Ctrl+D). Probably console in Windows have some similar modes.

ony
Thank you. Sounds truthfully, but if you see the bug description: it is really exaclty what I was asking, so for now I am going to mark answer of Artelius.
Steves