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

Lanny Ripple lanny at cisco.com
Mon Sep 24 10:57:38 EDT 2007

Well aa isn't returning a string.  It's returning a function for 
later evaluation which encapsulates the string.  It's like 
driving anywhere in California.  You can't get there following 
the road signs unless you've driven there once before.  In this 
case the road signs say "return a string" but the way to get 
their is "return a string encapsulated in a function".  The error 
message ("you can't get there from here") is then straightforward.


Andrew Coppin wrote:
>> aa :: String -> String
>> aa instr = do
>>   putStrLn "abc"
>>   putStrLn "abc"
>>   return "Az"
 >>   Couldn't match expected type `[t]' against inferred type 
`IO ()'

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

Lanny Ripple <lanny at cisco.com>
ScmDB / Cisco Systems, Inc.

More information about the Haskell-Cafe mailing list