【发布时间】:2020-05-03 19:36:55
【问题描述】:
我想写一个简单的游戏“猜数字”——尝试n。我想添加一些条件和命中。是否可以在 do 块内使用 guards ?
这是我的代码:
game = return()
game n = do putStrLn "guess number: 0-99"
number<-getLine
let y = read number
let x =20
| y>x = putStrLn "your number is greater than x"
| y<x = putStrLn "your number is less than x"
| y==x putStrLn "U win!!"
| otherwise = game (n-1)
已经出错了
error: parse error on input ‘|’
是否可以通过一些 空白 来解决,还是根本无法解决?
【问题讨论】:
标签: haskell syntax do-notation guard-clause