Lokman
Lokman

Reputation: 63

What is the meaning of xor = (/=)?

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

Answers (2)

willeM_ Van Onsem
willeM_ Van Onsem

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 Bools, 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

Jonas Høgh
Jonas Høgh

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

Related Questions