# MIT License, Copyright (c) 2022 Marvin Borner # with help from Justine Tunney # classic Church style numerals :import std/Logic . :import std/Combinator . :import std/Pair . # returns true if a unary number is zero zero? [0 [(+0u)] true] ⧗ Unary → Boolean =?‣ zero? :test (=?(+0u)) (true) :test (=?(+42u)) (false) # adds 1 to a unary number inc [[[1 (2 1 0)]]] ⧗ Unary → Unary ++‣ inc :test (++(+0u)) ((+1u)) :test (++(+1u)) ((+2u)) :test (++(+42u)) ((+43u)) # subs 1 from a unary number dec [[[2 [[0 (1 3)]] [1] [0]]]] ⧗ Unary → Unary --‣ dec :test (--(+0u)) ((+0u)) :test (--(+1u)) ((+0u)) :test (--(+42u)) ((+41u)) # adds two unary numbers add [[[[3 1 (2 1 0)]]]] ⧗ Unary → Unary → Unary …+… add :test ((+0u) + (+2u)) ((+2u)) :test ((+5u) + (+3u)) ((+8u)) # subs two unary numbers sub [[0 dec 1]] ⧗ Unary → Unary → Unary …-… sub :test ((+2u) - (+2u)) ((+0u)) :test ((+5u) - (+3u)) ((+2u)) # returns true if number is less than or equal to other number leq? [[=?(1 - 0)]] ⧗ Unary → Unary → Boolean …≤?… leq? :test ((+1u) ≤? (+2u)) (true) :test ((+2u) ≤? (+2u)) (true) :test ((+3u) ≤? (+2u)) (false) # returns true if number is greater than or equal to other number geq? \leq? ⧗ Unary → Unary → Boolean …≥?… geq? :test ((+1u) ≥? (+2u)) (false) :test ((+2u) ≥? (+2u)) (true) :test ((+3u) ≥? (+2u)) (true) # returns true if number is greater than other number # larger numbers should be second argument (performance) gre? [[¬(1 ≤? 0)]] ⧗ Unary → Unary → Boolean …>?… gre? :test ((+1u) >? (+2u)) (false) :test ((+2u) >? (+2u)) (false) :test ((+3u) >? (+2u)) (true) # returns true if number is less than other number # smaller numbers should be second argument (performance) les? \gre? ⧗ Unary → Unary → Boolean …