input <- readLn
if (input == 0)
then
putStr "0"
else if (input ==1)
then
putStr "1"
else if (input ==2)
在这种塞纳里奥如何在then
或else if
使用多个putStr用?哈斯克尔的if else
当我试图得到一个错误
Type error in application
*** Expression : putStr "0" putStr "0"
*** Term : putStr
*** Type : String -> IO()
*** Does not match : a -> b -> c -> d
这并不回答你的问题,但我希望你认识到这将会更好地写成模式匹配。 'case case input of 0 - > ... 1 - > ...' – Chuck 2011-06-08 19:28:47
@Chuck IO模式匹配是可能的,因为它是一个IO程序 – Sudantha 2011-06-09 03:24:52