roc/builtins/Bool.roc
2019-09-26 15:11:40 +03:00

31 lines
1.5 KiB
Text

api Bool provides Bool.*, not, equal, notEqual
## Either @True or @False.
Bool := False, True
## Returns @False when given @True, and vice versa.
not : Bool -> Bool
not = \bool ->
case bool when
False -> True
True -> False
## Returns @True if the two values are *structurally equal*, and @False otherwise.
##
## Structural equality works as follows:
##
## 1. @Int and @Float values are equal if their numbers are equal.
## 2. Records are equal if all their fields are equal.
## 3. Custom type variants (including the @True and @False variants of the @Bool custom type) are equal if they are the same variant, and also their contents (if any) are equal.
## 4. Collections (@String, @List, @Map, @Set, and @Bytes) are equal if they are the same length, and also all their corresponding elements are equal.
## 5. All functions are considered equal. (So `Bool.not == Bool.not` will return @True, as you might expect, but also `Num.abs == Num.negate` will return @True, as you might not. This design is because function equality has been formally proven to be undecidable in the general case, and returning @True in all cases turns out to be mostly harmless - especially compared to alternative designs like crashing, making @equal inconvenient to use, and so on.)
##
## This is the same as the @== operator.
eq : val, val -> Bool
## Calls @eq on the given values, then calls @not on the result.
##
## This is the same as the @=/= operator.
notEq : val, val -> Bool
notEq = \left right ->
not (equal left right)