aboutsummaryrefslogtreecommitdiff
path: root/std/magic/booleans.pk
diff options
context:
space:
mode:
Diffstat (limited to 'std/magic/booleans.pk')
-rw-r--r--std/magic/booleans.pk42
1 files changed, 42 insertions, 0 deletions
diff --git a/std/magic/booleans.pk b/std/magic/booleans.pk
new file mode 100644
index 0000000..3c7e28e
--- /dev/null
+++ b/std/magic/booleans.pk
@@ -0,0 +1,42 @@
+## std.booleans: Booleans and related types. Mostly compiler magic.
+## A stub module for documentation.
+
+pub type unit = union[sole]
+pub type bool = union[false, true]
+
+# note: puck could resolve kleene.false vs bool.false...
+# this is probably not worth it compared to improved type inference
+# pub type Kleene = union[False, Maybe, True]
+
+## Boolean equality
+pub func ==(a: bool, b: bool): bool =
+ match a
+ of (true, true), (false, false): true
+ of (false, true), (true, false): false
+
+pub func !=(a: bool, b: bool): bool =
+ not a == b
+
+## Boolean negation
+pub func not(a: bool): bool =
+ match a
+ of true: false
+ of false: true
+
+## Boolean conjunction
+pub func and(a: bool, b: bool): bool =
+ match (a, b)
+ of (true, true): true
+ of _: false
+
+## Boolean disjunction
+pub func or(a: bool, b: bool): bool =
+ match (a, b)
+ of (false, false): false
+ of _: true
+
+## Boolean exclusive disjunction
+pub func xor(a: bool, b: bool): bool =
+ match (a, b)
+ of (true, true), (false, false): false
+ of (true, false), (false, true): true