Skip to main content

Bool

Reference for mo:core/Bool in the core library.

Bool is mostly inline pure logic plus an iterator over both truth values. Use these helpers when higher-order APIs need named comparison, text, or enumeration functions instead of raw operators.

Import

mo:core/Bool

Status

  • Runtime module

Public API

Types

  • Bool

Functions

logicalAnd(a : Bool, b : Bool) : Bool

Evaluates the corresponding Boolean connective.

Contract

ensures result == (a and b);

Use when: code or specifications need this operation with the documented contract.

logicalOr(a : Bool, b : Bool) : Bool

Evaluates the corresponding Boolean connective.

Contract

ensures result == (a or b);

Use when: code or specifications need this operation with the documented contract.

logicalXor(a : Bool, b : Bool) : Bool

Evaluates the corresponding Boolean connective.

Contract

ensures result == (a != b);

Use when: code or specifications need this operation with the documented contract.

logicalNot(bool : Bool) : Bool

Evaluates the corresponding Boolean connective.

Contract

ensures result == (not bool);

Use when: code or specifications need this operation with the documented contract.

equal(a : Bool, b : Bool) : Bool

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == (a == b);

Use when: code or contracts need an explicit comparison helper instead of an operator.

compare(a : Bool, b : Bool) : Types.Order

Compares the supplied values and relates the result to the underlying order.

Contract

ensures result == #equal ==> a == b;
ensures result == #greater ==> (a and not b);
ensures result == #less ==> (not a and b);
ensures a == b ==> result == #equal;
ensures (a and not b) ==> result == #greater;
ensures (not a and b) ==> result == #less;

Use when: code or contracts need an explicit comparison helper instead of an operator.

toText(bool : Bool) : Text

Converts between the module type and the target representation.

Contract

ensures result == (if (bool) { "true" } else { "false" });

Use when: crossing between this module's value and another representation.

allValues() : Iter.Iter<Bool>

Creates an iterator over the requested numeric range or domain.

Contract

ensures Iter.Spec.contains<Bool>(result, true);
ensures Iter.Spec.contains<Bool>(result, false);

Use when: iteration boundaries should be explicit in code and examples.

Summary

  • Runtime module under mo:core/Bool.
  • Exposes 8 public functions.