Following are the logical operators
supported by Haskell.
Operator
|
Description
|
&&
|
'a && b' returns true if both
a, b are True. Else False.
|
||
|
'a || b' return False, if both a and b
are False, else True.
|
Not
|
'not a' Returns True if a is False,
True otherwise
|
*Main> let a = True *Main> let b = True *Main> let c = False *Main> *Main> a && b True *Main> a && c False *Main> *Main> a || b True *Main> a || c True *Main> a || False True *Main> c || (10 < 9) False *Main> *Main> not a False *Main> not b False *Main> not c True
Operators are implemented as functions
internally.
True && False is represented as
'(&&) True False', note that the function name must be enclosed in
parenthesis.
*Main> (&&) a b True *Main> (&&) a c False *Main> *Main> (||) a b True *Main> (||) a c True *Main> (||) a False True *Main> (||) c (10 < 9) False *Main>
No comments:
Post a Comment