Why does GHC infer type of `IO b` for an application of `hSetBuffering`?
I am trying to use hSetBuffering
in a Haskell program using GHC 6.10. When I try this very simple program:
module Ctlc
where
import IO
main :: ()
main = do hSetBuffering stdout NoBuffering
return ()
I get a baffling error message:
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 ()
I don't get why GHC is inferring a type of IO b
, since ghci claims
Prelude Data.List IO> :t hSetBuffering
hSetBuffering :: Handle -> BufferMode -> IO ()
ANSWER : I stupidly put the wrong type on main
. Thanks ja for sharp eyes.
你声明main是类型(),而不是IO()。
该函数必须具有某种IO类型,因为实现将执行系统调用。
链接地址: http://www.djcxy.com/p/33148.html上一篇: 如何选择正确的Haskell C型?