[Haskell-cafe] Noob question and sequence of operations (print then do something else)

Andrew Coppin andrewcoppin at btinternet.com
Mon Sep 24 03:15:26 EDT 2007

John Wicket wrote:
> Sorry, I was actually trying to use this as an example for something 
> more complicated I am trying to do.  In this example, why would the 
> inferred type be "IO ()"
> aa :: String -> String
> aa instr = do
>   putStrLn "abc"
>   putStrLn "abc"
>   return "Az"
>   Couldn't match expected type `[t]' against inferred type `IO ()'
>     In the expression: putStrLn "abc"
>     In a 'do' expression: putStrLn "abc"
>     In the expression:
>     do putStrLn "abc"
>        putStrLn "abc"
>        return "Az"

If you change that type signature to

  aa :: String -> IO String

then it will work.

Any code that does any I/O must have a result type "IO blah". If the 
code returns no useful information, it will be "IO ()". If, like above, 
it returns a string, it will be "IO String". And so on.

(I must say, that error message doesn't make it terribly clear what the 
problem is...)

More information about the Haskell-Cafe mailing list