What is the OR operator in Haskell?
Overview
The OR operator is used to evaluate two expressions. We can write a double pipe || to use the OR operator. It will return either a True or a False based on the conditions.
Syntax
expression1 || expression2
Return value
It returns a boolean value based on the given expressions.
Let's take a look at the truth table for OR.
The OR truth table
Expression 1 | Expression 2 | Result |
False | False | False |
False | True | True |
True | False | True |
True | True | True |
From the table above, we can conclude that if any one of the expressions is evaluated as True, then the result will be True.
Let's take a look at an example of this.
Example
main::IO()main = doprint( 5<10 || 36<25 )
Explanation
In the above code snippet:
- Line 4: We have two expressions, where the first expression evaluates to
Truewhile the second expression evaluates toFalse, and theORoperator returnsTrueaccording to the above table.