我在努力学习Haskell,我犯了这个错误。
parse error on input `='这里是我的代码:
nAnd1 :: Bool -> Bool -> Bool
nAnd x y = if (x==False && y == False) || x/=y then True else False
nAnd2 :: Bool -> Bool -> Bool
nAnd x y | if ((x == False && y == False) || x/=y) = True
| otherwise = False错误发生的地方在nAnd2中True之前的"=“处。有解决办法吗?
发布于 2020-09-25 10:58:21
放弃if的答案已经给出了。我想这个练习的意思是不同的。nAnd的意思是"not and",即
nAnd a b = not (a && b)但你有nAnd x y = (not x && not y) || x /= y。这很奇怪,我怀疑这是一个X-Y问题。你从真值表中得到了nand的定义吗?
a | b | a `nAnd` b
-----+-----+----------
False|False| True
False|True | True
True |False| True
True |True | False然后花时间重写真值表
a | b | a `nAnd` b
-----+-----+----------
True |True | False
* | * | True并使用模式匹配:
nAnd :: Bool -> Bool -> Bool
nAnd True True = False
nAnd _ _ = Truehttps://stackoverflow.com/questions/64061356
复制相似问题