我是Haskell的新手,很高興能有人願意幫助我!我試圖讓這個程序與do while while循環一起工作。Haskell - 做while循環
從第二函數getline命令,結果被放入varible goGlenn如果goGlenn不等於「開始」,然後該程序將返回到開始
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")
要添加到@志的回答,代碼你寫的或多或少都是正確的Haskell語法,但是'loop'和'while'這樣的東西沒有內建.Haskell實際上並沒有do-while循環,它有你可以用來實現的遞歸do-while循環。 Haskell實際上並沒有循環,只是遞歸,你必須學習如何從你使用的命令式語言中重新實現功能。 – bheklilr
@bheklilr儘管我猜gallais在他們的評論中是正確的:上面的代碼似乎是從Control.Monad.LoopWhile文檔改編的。 – chi