所以,我想prog
用>>
/>>=
绑定而不是do
and重写给定的函数<-
:
prog :: IO Int
prog =
do putStrLn "Hello there! How old are you?"
age <- (readLn :: IO Int)
let agedays = show $ age * 365
putStrLn $ "So you are at least than " ++ agedays ++ " days old."
return (read agedays)
重写更简单的函数对我来说不是问题,但是readLn :: IO Int
让我很头疼......
我的建议是:
prog :: IO Int
prog =
putStrLn "Hello there!How old are you?" >>
readLn::IO >>=
let agedays = \age -> show $ age * 365 >>
putStrLn $ "So you are at least than " ++ agedays ++ " days old."
但是,这不起作用,因为将 绑定readLn :: IO
到下一个匿名函数存在问题\age
。有什么帮助吗?