I found the code of logical gate xor written in Haskell, but I don't know what does this " (/=)
" mean!
xor :: Bool -> Bool -> Bool
xor = (/=)
(/=):: Eq a => a -> a -> Bool
is a function defined in the Eq
typeclass. It tests if two items are different and returns True
in that case. For Bool
s, it thus checks if the first bool is different than the other bool, which is what a xor gate does:
x |
y |
x /= y |
x `xor` y |
---|---|---|---|
False |
False |
False |
False |
False |
True |
True |
True |
True |
False |
True |
True |
True |
True |
False |
False |
/= is the not equal operator. It is equivalent to xor for booleans, since xor is only true when the booleans have different values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.