我知道我能做到这一点...使用警卫分配一些第一
isZero :: Int -> Bool
isZero x
| x == 0 = True
| otherwise = False
但我可以做这样的事情后的变量?
isPalindrome :: Int -> Bool
isPalindrome x
let digitList = intToDigits x -- Decomposes the integer into
-- digits, i.e. 37 -> [3, 7]
| digitList == reverse digitList = True
| otherwise = False
这会导致编译错误,但我相信你知道我在做什么。
使用语言的条件表达式(“if/then/else”,case语句或警卫)返回“Bool”通常意味着有一个等值ent单个表达式,计算出正确的'Bool'。 – 2011-04-30 02:06:29