Search code examples
haskellxorghci

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

Solution

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