Question

Je suis en train d'utiliser hSetBuffering dans un programme Haskell utilisant GHC 6.10. Lorsque je tente ce programme très simple:

module Ctlc
where

import IO

main :: ()
main = do hSetBuffering stdout NoBuffering
          return ()

Je reçois un message d'erreur déconcertante:

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 ()

Je ne comprends pas pourquoi GHC infère un type de IO b, puisque les revendications ghci

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

Réponse : Je mets bêtement le mauvais type sur main. Merci ja pour les yeux pointus.

Était-ce utile?

La solution

Vous avez déclaré être principal de type (), non IO ().

Autres conseils

Cette fonction doit avoir un certain type IO, parce que la mise en œuvre va faire un appel système.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top