19.13 Boolean expressions exp andalso exp and exp orelse exp
The boolean type is predefined as follows:
datatype bool = false | true
The name of data constructors usually begins with an capital letter, these two constructors are exceptions of such a convention.
For any two expressions exp and exp of bool type, the following constructs are provided.
-
•
Logical conjunction:exp andalso exp
It evaluates exp at first. If the value of exp is true, then it evaluates exp and returns its value as the result of the entire expression. Otherwise, the value of this expression is false. In this case, exp is not evaluated.
-
•
Logical disjunction:exp orelse exp
It evaluates exp at first. If the value of exp is false, then it evaluates exp and returns its value as the result of the entire expression. Otherwise, the value of this expression is true. In this case, exp is not evaluated.
Since it may ignore the second expressions, these operations are provided as language constructs, not functions.
These syntaxes are left-associative and in the same precedence. Therefore,
false andalso true orelse false
is interpreted as (false andalso true) orelse false and hence is evaluated to false.
Other operations on bool type are provided as functions. For example,
not : bool -> bool