[Haskell] How to read one char from stdin and return immediately?

Haihua Lin HaihuaLin at 163.com
Fri Aug 18 08:09:50 EDT 2006


Hi all,

How to read one char from stdin and return immediately?
I mean there is no need to wait the user input a return.

For example:
Print "y/n: "
Users input y, return immediately, no return need.

I have tried code as below, but it didn't work for me.

import IO

main = do
         hSetBuffering stdout NoBuffering            
         putStr   "Y/N: "
         c <- getChar
         putStr ("Your input is " ++ show c++".\n")

Thanks very much.

Best regards,
Haihua Lin




More information about the Haskell mailing list