为什么GHC会推断出`hSetBuffering`的应用程序`IO b`的类型?

Nor*_*sey 3 haskell typeerror

我试图hSetBuffering在使用GHC 6.10的Haskell程序中使用.当我尝试这个非常简单的程序时:

module Ctlc
where

import IO

main :: ()
main = do hSetBuffering stdout NoBuffering
          return ()
Run Code Online (Sandbox Code Playgroud)

我收到一个令人困惑的错误消息:

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 ()
Run Code Online (Sandbox Code Playgroud)

我不明白为什么 GHC推断出一种类型IO b,因为ghci声称

Prelude Data.List IO> :t hSetBuffering
hSetBuffering :: Handle -> BufferMode -> IO ()
Run Code Online (Sandbox Code Playgroud)

答案:我愚蠢地把错误的类型打开了main.感谢JA的眼睛是雪亮的.

ja.*_*ja. 8

您已将main声明为type(),而不是IO().