Compare in Haskell

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

To compare numbers in Haskell, we use various comparison operators. Here are some of the common operators used in Haskell:

1. < (less than)
2. > (greater than)
3. <= (less than or equal to)
4. >= (greater than or equal to)
5. == (equal to)
6. /= (not equal to)

For example, let's say we have two numbers a and b. We can compare them using these operators in the following way:

a < b -- returns True if a is less than b, otherwise False
a > b -- returns True if a is greater than b, otherwise False
a <= b -- returns True if a is less than or equal to b, otherwise False
a >= b -- returns True if a is greater than or equal to b, otherwise False
a == b -- returns True if a is equal to b, otherwise False
a /= b -- returns True if a is not equal to b, otherwise False

Here are some examples:

-- declaring two numbers
a = 5
b = 10

-- comparing the numbers
a < b -- returns True
a > b -- returns False
a <= b -- returns True
a >= b -- returns False
a == b -- returns False
a /= b -- returns True

In the above example, we declare two numbers a = 5 and b = 10 and then we compare them using various comparison operators.