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 isTrue.&&- Boolean and - returns true only if both options areTrue.not- Boolean negation - returns the opposite value of the input.xor- Boolean exclusive-or - returns True if exactly one input isTrue.
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 -----------------------
I am struggling with this boolean operation:
4| True && 0
^
Both sides of (&&) must be Bool values, but the right side is:
number
Hint: Only Int and Float values work as numbers.Look how helpful the error messages are. It’s one of many reasons why Elm is such a delightful language.