【发布时间】:2016-06-08 22:44:23
【问题描述】:
我是 Haskell 的新手,如果有人愿意帮助我,我会很高兴!我试图让这个程序与 do while 循环一起工作。
第二个 getLine 命令的结果被放入变量 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")
【问题讨论】:
-
补充@chi 的答案,您编写的代码或多或少是正确的Haskell 语法,但没有内置
loop和while之类的东西。Haskell 没有t 实际上有 do-while 循环,它具有可用于实现 do-while 循环的递归。 Haskell 实际上根本没有循环,只有递归,您必须学习如何从您使用的命令式语言中重新实现功能。 -
@bheklilr 我猜加莱在他们下面的评论中是对的:上面的代码似乎改编自
Control.Monad.LoopWhile文档。
标签: haskell while-loop do-while