为什么GHC为`hSetBuffering`的应用程序推断`IO b`的类型?
我正在尝试在使用GHC 6.10的Haskell程序中使用hSetBuffering
。 当我尝试这个非常简单的程序时:
module Ctlc
where
import IO
main :: ()
main = do hSetBuffering stdout NoBuffering
return ()
我收到一个莫名其妙的错误信息:
ctlc.hs:8:10:
Couldn't match expected type `()' against inferred type `IO b'
In a stmt of a 'do' expression: hSetBuffering stdout NoBuffering
In the expression:
do hSetBuffering stdout NoBuffering
return ()
In the definition of `main':
main = do hSetBuffering stdout NoBuffering
return ()
因为ghci声称,我不明白为什么GHC推断IO b
类型
Prelude Data.List IO> :t hSetBuffering
hSetBuffering :: Handle -> BufferMode -> IO ()
回答 :我愚蠢地把错误的类型放在main
。 谢谢你犀利的眼睛。
你声明main是类型(),而不是IO()。
该函数必须具有某种IO类型,因为实现将执行系统调用。
链接地址: http://www.djcxy.com/p/33147.html上一篇: Why does GHC infer type of `IO b` for an application of `hSetBuffering`?