开发者

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

Prelud开发者_如何学Ce Data.List IO> :t hSetBuffering
hSetBuffering :: Handle -> BufferMode -> IO ()

ANSWER: I stupidly put the wrong type on main. Thanks ja for sharp eyes.


You've declared main to be of type (), not IO ().


That function has to have some IO type, because the implementation is going to do a system call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜