Bool

Eq implements is_eq : a, a -> Bool where a implements Eq

Defines a type that can be compared for total equality.

Total equality means that all values of the type can be compared to each other, and two values a, b are identical if and only if isEq(a, b) is Bool.true.

Not all types support total equality. For example, F32 and F64 can be a NaN (Not a Number), and the IEEE-754 floating point standard specifies that two NaNs are not equal.

Bool

Represents the boolean true and false using an opaque type. Bool implements the Eq ability.

true : Bool

The boolean true value.

false : Bool

The boolean false value.

and : Bool, Bool -> Bool

Returns Bool.true when both inputs are Bool.true. This is equivalent to the logic AND gate. The infix operator && can also be used as shorthand for Bool.and.

expect Bool.and(Bool.true, Bool.true) == Bool.true
expect (Bool.true && Bool.true) == Bool.true
expect (Bool.false && Bool.true) == Bool.false
expect (Bool.true && Bool.false) == Bool.false
expect (Bool.false && Bool.false) == Bool.false

Performance Details

In Roc the && and || work the same way as any other function. However, in some languages && and || are special-cased. In these languages the compiler will skip evaluating the expression after the first operator under certain circumstances. For example an expression like enable_pets && likes_dogs(user) would compile to.

if enable_pets then
    likes_dogs(user)
else
    Bool.false

Roc does not do this because conditionals like if and when have a performance cost. Calling a function can sometimes be faster across the board than doing an if to decide whether to skip calling it.

or : Bool, Bool -> Bool

Returns Bool.true when either input is a Bool.true. This is equivalent to the logic OR gate. The infix operator || can also be used as shorthand for Bool.or.

expect Bool.or(Bool.false, Bool.true) == Bool.true
expect (Bool.true || Bool.true) == Bool.true
expect (Bool.false || Bool.true) == Bool.true
expect (Bool.true || Bool.false) == Bool.true
expect (Bool.false || Bool.false) == Bool.false

Performance Details

In Roc the && and || work the same way as any other functions. However, in some languages && and || are special-cased. Refer to the note in Bool.and for more detail.

not : Bool -> Bool

Returns Bool.false when given Bool.true, and vice versa. This is equivalent to the logic NOT gate. The operator ! can also be used as shorthand for Bool.not.

expect Bool.not(Bool.false) == Bool.true
expect !Bool.false == Bool.true

is_not_eq : a, a -> Bool where a implements Eq

This will call the function Bool.is_eq on the inputs, and then Bool.not on the result. The is equivalent to the logic XOR gate. The infix operator != can also be used as shorthand for Bool.is_not_eq.

Note that is_not_eq does not accept arguments whose types contain functions.

expect Bool.is_not_eq(Bool.false, Bool.true) == Bool.true
expect (Bool.false != Bool.false) == Bool.false
expect "Apples" != "Oranges"