Reputation: 63
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 = (/=)
Upvotes: 3
Views: 153
Reputation: 477265
(/=) :: 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 |
Upvotes: 8
Reputation: 10874
/= is the not equal operator. It is equivalent to xor for booleans, since xor is only true when the booleans have different values.
Upvotes: 7