3.3

Boolean

Performing operations from boolean algebra is also quite straightforward in Elm.

> True || False
True

> False || False
False

> True && False
False

> True && True
True

> not True
False

> xor True False
True

> xor True True
False

> xor False False
False
  • || - Boolean or - returns true if at least one input is True.
  • && - Boolean and - returns true only if both options are True.
  • not - Boolean negation - returns the opposite value of the input.
  • xor - Boolean exclusive-or - returns True if exactly one input is True.

Some programming languages treat the number zero or null as synonymous with False. Elm doesn’t allow that, nor does it consider a non-zero value to be True. For a condition to be true, it must evaluate exactly to the value True.

> True && 0

----------------- TYPE MISMATCH -----------------------
The right argument of (&&) is causing a type mismatch.

3|   True && 0
             ^
(&&) is expecting the right argument to be a:

    Bool

But the right argument is:

    number
Back to top

New chapters are coming soon!

Sign up for the Elm Programming newsletter to get notified!

* indicates required
Close