Not in Haskell

Find this useful? Support us: Star on GitHub 6
Category: Other | Language: Haskell

In Haskell, not is a Boolean negation operator that takes a single argument of type Bool and returns a Boolean value that is the opposite of the argument. If the argument is True, not will return False and vice versa.

Here are some examples showing how to use not in Haskell:

not True      -- returns False
not False     -- returns True

-- A function that negates the result of another function
isEven n = n mod 2 == 0
isOdd = not . isEven

isOdd 3 -- returns True, because 3 is odd
isOdd 4 -- returns False, because 4 is even

In the first two examples, not is used with literal Boolean values True and False. In the last two examples, not is used in combination with function composition to build a new function that negates the result of another function.