小编Sar*_*lin的帖子

关于hFlush和惰性评估的问题

我具有相同功能的三个定义:

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。为什么是这样?

io monads haskell lazy-evaluation pointfree

2
推荐指数
1
解决办法
56
查看次数

标签 统计

haskell ×1

io ×1

lazy-evaluation ×1

monads ×1

pointfree ×1