Home > Software engineering >  What is the meaning of xor = (/=)?
What is the meaning of xor = (/=)?

Time:11-18

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 = (/=)

CodePudding user response:

/= is the not equal operator. It is equivalent to xor for booleans, since xor is only true when the booleans have different values.

CodePudding user response:

(/=) :: 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
  • Related