我正在尝试制作游戏,我想向玩家提问。如果他们的答案是肯定的,那么就会发生一些事情或者没有其他事情发生。
class Status a where
stat :: a -> String
instance Status Char where
stat _ = "Would you like to drink a potion? YES or NO?"
这样做将检查所有Char类型,但我不能使用String。我可以用不同的方式做到这一点吗?
答案 0 :(得分:1)
我认为这就是你想要的
main = do
putStrLn "type yes or no"
response <- getLine
if response == "yes"
then putStrLn "You typed yes"
else putStrLn "You didn't type yes"
答案 1 :(得分:0)
听起来你想要这样的东西:
import Data.Char
getStatus :: String -> IO Bool
getStatus question = do
putStrLn (question ++ " YES or NO?")
response <- getLine
return (toLower response == "y")
main = do
res1 <- getStatus "question1?"
res2 <- getStatus "question2?"
.
.
.
res20 <- getStatus "question20?"
doSomething [res1, ..., res20]