SML# Document Version 4.1.0
19 Expressions

19.13 Boolean expressions exp1 andalso exp2 and exp1 orelse exp2

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 exp1 and exp2 of bool type, the following constructs are provided.

  • Logical conjunction:exp1 andalso exp2

    It evaluates exp1 at first. If the value of exp1 is true, then it evaluates exp2 and returns its value as the result of the entire expression. Otherwise, the value of this expression is false. In this case, exp2 is not evaluated.

  • Logical disjunction:exp1 orelse exp2

    It evaluates exp1 at first. If the value of exp1 is false, then it evaluates exp2 and returns its value as the result of the entire expression. Otherwise, the value of this expression is true. In this case, exp2 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