Why does the GHC return the type `IO b` for applying` hSetBuffering`?

I am trying to use hSetBufferingin 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 an 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 understand why GHC deduces type IO b, since ghci claims

Prelude Data.List IO> :t hSetBuffering
hSetBuffering :: Handle -> BufferMode -> IO ()

ANSWER : I stupidly put the wrong type on main. Thank you ja for your sharp eyes.

+3
source share
2 answers

You indicated that main is of type (), not IO ().

+8
source

This function must have some type of I / O, because the implementation will make a system call.

0
source

Source: https://habr.com/ru/post/1734732/


All Articles