Skip to content

Bool

A Bool is true or false. Comparisons give one, and and, or and not combine them:

3 < 4 and not (1 > 2)
true

and and or short-circuit: the right side is evaluated only when the left side does not already give the answer. false and x is false without evaluating x.

A Bool is not a number, and compares only with another Bool:

true == 1
check error[type-mismatch]: `Eq` for Bool compares with Bool, not Int
 --> <expression>:1:1
  |
1 | true == 1
  | ^^^^^^^^^

A condition must be a Bool. a given condition otherwise b chooses a value by one:

pages = 412
"long" given pages > 300 otherwise "short"
"long"

A Bool has no order, so < and sort reject it:

true < false
check error[type-mismatch]: `<` requires two values of the same Orderable type, not Bool and Bool
 --> <expression>:1:1
  |
1 | true < false
  | ^^^^^^^^^^^^