Friday, 29 April 2016

Haskell: Comparison operators

Comparison operators determine if one operand is greater than, less than, equal to, or not equal to another operand.


Operator
Description
Example
==
Equal to

a==b returns true if a is equal to b, else false
/=
Not equal to

a/=b returns true if a is not equal to b, else false.
> 
Greater than
a>b returns true, if a is > b, else false
>=

Greater than or equal to
a>=b returns true, if a is >= b, else false.
< 
Less than
a<b returns true, if a is < b, else false.
<=

Less than or equal to
a<=b returns true, if a is <= b, else false.

*Main> let a = 10
*Main> let b = 12
*Main> 
*Main> a == b
False
*Main> a /= b
True
*Main> a > b
False
*Main> a < b
True
*Main> a >= b
False
*Main> a <= b
True

Operators are implemented as functions internally.

10 == 12 is represented as '(==) 10 12', note that the function name must be enclosed in parenthesis.
*Main> (==) 10 12
False
*Main> (/=) 10 12
True
*Main> (>) 10 12
False
*Main> (<) 10 12
True
*Main> (>=) 10 12
False
*Main> (<=) 10 12
True




Previous                                                 Next                                                 Home

No comments:

Post a Comment