[Haskell-beginners] A basic misunderstanding of how to program with IO

Isaac Dupree ml at isaac.cedarswampstudios.org
Sun May 9 18:13:48 EDT 2010

On 05/08/10 11:55, Ken Overton wrote:
> Sorry for such a beginner-y question, but is there a way to make a function like:
>      interact :: String ->  Resp
>      interact txt =
> 		putStrLn txt
> 		rsp<- getLine
> 		return parseResp rsp
>      parseResp :: String ->  Resp
> Or is that simply a wrong way of programming in Haskell with IO?

I think, yes your function looks close to typical Haskell, you're just 
missing a "do", a pair of parentheses, and an "IO":

     interact :: String -> IO Resp
     interact txt = do
		putStrLn txt
		rsp <- getLine
		return (parseResp rsp)

     parseResp :: String -> Resp

Does that make sense to you?  Would you like more detailed explanation 
of the changes?


More information about the Beginners mailing list