aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Number/Scott.bruijn
diff options
context:
space:
mode:
Diffstat (limited to 'std/Number/Scott.bruijn')
-rw-r--r--std/Number/Scott.bruijn31
1 files changed, 31 insertions, 0 deletions
diff --git a/std/Number/Scott.bruijn b/std/Number/Scott.bruijn
new file mode 100644
index 0000000..bc776d8
--- /dev/null
+++ b/std/Number/Scott.bruijn
@@ -0,0 +1,31 @@
+# MIT License, Copyright (c) 2023 Marvin Borner
+
+:import std/Combinator .
+:import std/Logic .
+
+zero [[1]] ⧗ Scott
+
+inc [[[0 2]]] ⧗ Scott → Scott
+
+:test (inc zero) ([[0 zero]])
+:test (inc (inc zero)) ([[0 [[0 zero]]]])
+:test (inc (inc (inc zero))) ([[0 [[0 [[0 zero]]]]]])
+
+dec [0 zero [0]] ⧗ Scott → Scott
+
+:test (dec zero) (zero)
+:test (dec (inc zero)) (zero)
+:test (dec (inc (inc zero))) (inc zero)
+
+zero? [0 true [false]] ⧗ Scott → Boolean
+
+:test (zero? zero) (true)
+:test (zero? (inc zero)) (false)
+:test (zero? (inc (inc zero))) (false)
+
+add z [[[1 0 [inc (3 0 1)]]]] ⧗ Scott → Scott → Scott
+
+:test (add zero zero) (zero)
+:test (add zero (inc zero)) (inc zero)
+:test (add (inc zero) zero) (inc zero)
+:test (add (inc zero) (inc zero)) (inc (inc zero))