这段代码是在haskell中定义排他析取真值表
单击此处了解有关异或 代码的更多信息:
-- truth table concept of logical XOR
exclusiveDisjunction :: Bool -> Bool -> Bool
exclusiveDisjunction = x y
|True True <- False
|True False <- True
|False True <- True
|False False <- False
|otherwise = x y
结果:
Ex6^.hs:31:5:
parse error on input ‘|’
Failed, modules loaded: none.
给定haskell语法中的异或真值表,如何使用两个布尔值设置警卫?
谢谢 请在不使用 haskell 内置运算符的情况下指定您的答案,这意味着不要使用 && ||。
为什么不能这样做?
exclusiveDisjunction2 :: Bool -> Bool -> Bool
exclusiveDisjunction2 x y
|True True = False
|True False = True
|False True = True
|False False = False
这是运行后的结果
Couldn't match expected type ‘Bool -> Bool’ with actual type ‘Bool’
The function ‘False’ is applied to one argument,
but its type ‘Bool’ has none
In the expression: False False
In a stmt of a pattern guard for
an equation for ‘exclusiveDisjunction2’:
False False