我具有相同功能的三个定义:
prompt :: String -> IO String
prompt = (getLine <*) . (hFlush stdout <*) . putStrLn
prompt' :: String -> IO String
prompt' str = do
putStrLn str
hFlush stdout
getLine
prompt'' :: String -> IO String
prompt'' str = putStrLn str >> hFlush stdout >> getLine
Run Code Online (Sandbox Code Playgroud)
prompt'并且prompt''都在运行前刷新标准输出getLine,但是不能prompt。为什么是这样?