A boolean has the type
bool and can be either
false. Common operations:
&&: logical and
||: logical or
not: logical not. Note that ! is reserved for something else
==: physical equal, compares data structures deeply:
(1, 2) == (1, 2)is
true. Convenient, but use with caution
===: referential equal, compares shallowly.
(1, 2) === (1, 2)is
let myTuple = (1, 2); myTuple === myTupleis
!=: physical unequal
!==: referential unequal
false, which aren't the same as the Reason/OCaml
false! Don't use them interchangeably without proper conversion (
Use physical equal tastefully. It's convenient, but might accidentally make you compare two deeply nested data structures and incur a big performance hit. It's also not always clear what counts as "equal". For example, is a piece of data
foo equal to a lazy
foo? Ideally, it'd have been pluggable. Future changes are coming to make this possible and reliable; if you're interested, check modular implicit.
This section assumes knowledge with variants. If it's your first time reading this guide, feel free to come back to this later!
Boolean is (only conceptually) a special case of a variant: