我是Haskell的新手,如果有人愿意帮助我,我会很高兴的!我试图让这个程序与do while循环一起工作。
第二个getLine命令的结果被放入varible goGlenn中,如果goGlenn不等于“start”,那么程序将返回到开头
start = do
loop $ do lift performAction
putStrLn "Hello, what is your name?"
name <- getLine
putStrLn ("Welcome to our personality test " ++ name ++ ", inspired by the Big Five Theory.")
putStrLn "You will receive fifty questions in total to which you can reply with Yes or No."
putStrLn "Whenever you feel ready to begin please write Start"
goGlenn <- getLine
putStrLn goGlenn
while (goGlenn /= "start")
答案 0 :(得分:10)
在Haskell中,你大多数时候递归地写“循环”。
Warning: Attempt to present ZoomViewController on MainViewController which is already presenting ModalViewNavigationController
答案 1 :(得分:3)
不确定,也许此版本可以帮助您:
import Control.Monad
loop action = do
condition <- action
when condition (loop action)
while = return
start =
let action = do {
putStrLn "Hello, what is your name?";
name <- getLine;
putStrLn ("Welcome to our personality test " ++ name ++ ", inspired by the Big Five Theory.");
putStrLn "You will receive fifty questions in total to which you can reply with Yes or No.";
putStrLn "Whenever you feel ready to begin please write Start";
goGlenn <- getLine;
putStrLn goGlenn;
while (goGlenn /= "start");
}
in loop action
(编辑)或者也可以:
start =
loop (do {
putStrLn "Hello, what is your name?";
name <- getLine;
putStrLn ("Welcome to our personality test " ++ name ++ ", inspired by the Big Five Theory.");
putStrLn "You will receive fifty questions in total to which you can reply with Yes or No.";
putStrLn "Whenever you feel ready to begin please write Start";
goGlenn <- getLine;
putStrLn goGlenn;
while (goGlenn /= "start");
})