diff options
-rw-r--r-- | samples/fun/interpreter.bruijn | 1 | ||||
-rw-r--r-- | src/Binary.hs | 2 | ||||
-rw-r--r-- | std/Combinator.bruijn | 8 | ||||
-rw-r--r-- | std/Number/Ternary.bruijn | 6 | ||||
-rw-r--r-- | std/Number/Unary.bruijn | 25 |
5 files changed, 30 insertions, 12 deletions
diff --git a/samples/fun/interpreter.bruijn b/samples/fun/interpreter.bruijn index 0691f4a..c2b8020 100644 --- a/samples/fun/interpreter.bruijn +++ b/samples/fun/interpreter.bruijn @@ -7,7 +7,6 @@ :import std/List . :import std/Char C -# TODO: finish types uni [0 0] int [0 Ω] ⧗ (List Bit) → Term int [[[0 go (2 2) 1]]] go [[[[2 match]]]] diff --git a/src/Binary.hs b/src/Binary.hs index 3f77d4a..acf20d4 100644 --- a/src/Binary.hs +++ b/src/Binary.hs @@ -61,8 +61,6 @@ fromJot = worker . reverse k = Function $ NormalFunction "k" worker ('0' : xs) = Application (Application (worker xs) s) k worker ('1' : xs) = Application s (Application k (worker xs)) - -- worker ('1' : xs) = Abstraction - -- (Abstraction (Application (worker xs) (Application (Bruijn 1) (Bruijn 0)))) worker _ = Abstraction (Bruijn 0) diff --git a/std/Combinator.bruijn b/std/Combinator.bruijn index 8efc534..71ad078 100644 --- a/std/Combinator.bruijn +++ b/std/Combinator.bruijn @@ -7,16 +7,22 @@ b [[[2 (1 0)]]] ⧗ (b → c) → (a → b) → a → c …∘… b +∘‣ b + # blackbird combinator: 2x function composition: (f ∘∘ g) x y = f (g x y) b' [[[[3 (2 1 0)]]]] ⧗ (c → d) → (a → b → c) → a → b → d …∘∘… b' +∘∘‣ b' + # bunting combinator: 3x function composition: (f ∘∘∘ g) x y z = f (g x y z) b'' [[[[[4 (3 2 1 0)]]]]] ⧗ (d → e) → (a → b → c → d) → a → b → c → e …∘∘∘… b'' +∘∘∘‣ b'' + # becard combinator b''' [[[[3 (2 (1 0))]]]] ⧗ (c → d) → (b → c) → (a → b) → a → d @@ -117,7 +123,7 @@ o [[0 (1 0)]] ⧗ ((a → b) → a) → (a → b) → b ψ* [[[[[4 3 (2 1) (2 0)]]]]] ⧗ (c → b → b → d) → c → (a → b) → a → a → d -# queer bird combinator: reverse function composition: (f , g) x = g (f x) +# queer bird combinator: reverse function composition q [[[1 (2 0)]]] ⧗ (a → b) → (b → c) → a → c # quixotic bird combinator diff --git a/std/Number/Ternary.bruijn b/std/Number/Ternary.bruijn index a0fd796..e9b402c 100644 --- a/std/Number/Ternary.bruijn +++ b/std/Number/Ternary.bruijn @@ -282,7 +282,7 @@ sub [[1 + -0]] ⧗ Number → Number → Number :test ((+42) - (+1) =? (+41)) (true) # returns true if number is greater than other number -gre? [[>?(1 - 0)]] ⧗ Number → Number → Boolean +gre? positive? ∘∘ sub ⧗ Number → Number → Boolean …>?… gre? @@ -300,7 +300,7 @@ les? \gre? ⧗ Number → Number → Boolean :test ((+3) <? (+2)) (false) # returns true if number is less than or equal to other number -leq? [[¬(1 >? 0)]] ⧗ Number → Number → Boolean +leq? not! ∘∘ gre? ⧗ Number → Number → Boolean …≤?… leq? @@ -317,7 +317,7 @@ geq? \leq? ⧗ Number → Number → Boolean :test ((+2) ≥? (+2)) (true) :test ((+3) ≥? (+2)) (true) -# returns eq, lt, gt depending on comparison of two functions +# returns eq, lt, gt depending on comparison of two numbers compare-case [[[[[go (1 - 0)]]]]] ⧗ a → b → c → Number → Number → d go [=?0 5 (>?0 4 3)] diff --git a/std/Number/Unary.bruijn b/std/Number/Unary.bruijn index f5de3e2..6ace440 100644 --- a/std/Number/Unary.bruijn +++ b/std/Number/Unary.bruijn @@ -63,7 +63,7 @@ sub [[0 dec 1]] ⧗ Unary → Unary → Unary :test ((+5u) - (+3u)) ((+2u)) # returns true if number is less than or equal to other number -leq? [[=?(1 - 0)]] ⧗ Unary → Unary → Boolean +leq? zero? ∘∘ sub ⧗ Unary → Unary → Boolean …≤?… leq? @@ -82,7 +82,7 @@ geq? \leq? ⧗ Unary → Unary → Boolean # returns true if number is greater than other number # larger numbers should be second argument (performance) -gre? [[¬(1 ≤? 0)]] ⧗ Unary → Unary → Boolean +gre? not! ∘∘ leq? ⧗ Unary → Unary → Boolean …>?… gre? @@ -101,12 +101,13 @@ les? \gre? ⧗ Unary → Unary → Boolean :test ((+3u) <? (+2u)) (false) # returns true if two unary numbers are equal -eq? [[(0 ≥? 1) ⋀? (0 ≤? 1)]] ⧗ Unary → Unary → Boolean +eq? [[=?(1 - 0) ⋀? =?(0 - 1)]] ⧗ Unary → Unary → Boolean …=?… eq? :test ((+1u) =? (+0u)) (false) :test ((+1u) =? (+1u)) (true) +:test ((+1u) =? (+2u)) (false) :test ((+42u) =? (+42u)) (true) # returns true if two unary numbers are not equal @@ -118,6 +119,20 @@ not-eq? not! ∘∘ eq? ⧗ Unary → Unary → Boolean :test ((+1u) ≠? (+1u)) (false) :test ((+42u) ≠? (+42u)) (false) +# returns eq, lt, gt depending on comparison of two numbers +compare-case [[[[[go (1 - 0) (0 - 1)]]]]] ⧗ a → b → c → Unary → Unary → d + go [[=?0 (=?1 6 5) 4]] + +# returns ternary 1 if a>b, -1 if a<b and 0 if a=b +# also: spaceship operator +compare compare-case (+0) (+1) (-1) ⧗ Unary → Unary → Number + +:test (compare (+2u) (+2u)) ((+0)) +:test (compare (+2u) (+1u)) ((+1)) +:test (compare (+1u) (+2u)) ((-1)) + +…<=>… compare + # muls two unary numbers mul …∘… ⧗ Unary → Unary → Unary @@ -136,7 +151,7 @@ div [[[[3 [[0 1]] [1] (3 [3 [[0 1]] [3 (0 1)] [0]] 0)]]]] ⧗ Unary → Unary � :test ((+2u) / (+2u)) ((+1u)) :test ((+2u) / (+3u)) ((+0u)) -# slower div +# slower div (more obvious impl) div* [z rec ++0] ⧗ Unary → Unary → Unary rec [[[[[[=?0 ((+0u) 2 1) (2 (5 0 3 2 1))] (3 - 2)]]]]] @@ -148,7 +163,7 @@ mod [[[[3 [0 [[1]]] (3 [3 [[[0 (2 (5 1)) 1]]] [1] 1] [1]) [[0]]]]]] ⧗ Unary � :test ((+10u) % (+3u)) ((+1u)) :test ((+3u) % (+5u)) ((+3u)) -# slower mod +# slower mod (more obvious impl) mod* [[1 [0 [[(0 ⋀? (3 ≤? 1)) case-rec case-end]]] (1 : true) [[1]]]] ⧗ Unary → Unary → Unary case-rec (1 - 3) : true case-end 1 : false |