diff options
author | Marvin Borner | 2023-10-19 12:54:42 +0200 |
---|---|---|
committer | Marvin Borner | 2023-10-19 12:54:42 +0200 |
commit | 0546c892748c77595fbd10357ede60c53a745be4 (patch) | |
tree | 818438806c0b6ac084dced4514c55e4bcd80390f /samples/fun | |
parent | 0c034a646822b74377c95b8934e8d5bb2cd1653e (diff) |
Added example mutual recurrence relations for y*
Diffstat (limited to 'samples/fun')
-rw-r--r-- | samples/fun/mutrec.bruijn | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/samples/fun/mutrec.bruijn b/samples/fun/mutrec.bruijn new file mode 100644 index 0000000..34042ff --- /dev/null +++ b/samples/fun/mutrec.bruijn @@ -0,0 +1,32 @@ +# some example usage of the variadic fixed point combinator + +:import std/List . +:import std/Logic . +:import std/Number . + +# generates odd? and even? function as list +odd-even? y* (even? : {}odd?) + even? [[[=?0 true (1 --0)]]] + odd? [[[=?0 false (2 --0)]]] + +:test (^odd-even? (+5)) (false) +:test (_odd-even? (+5)) (true) + +# calculates n % 3 +mod3 ^(y* (a : (b : {}c))) + a [[[[=?0 (+0) (2 --0)]]]] + b [[[[=?0 (+1) (1 --0)]]]] + c [[[[=?0 (+2) (3 --0)]]]] + +:test ((mod3 (+0)) =? (+0)) (true) +:test ((mod3 (+1)) =? (+1)) (true) +:test ((mod3 (+2)) =? (+2)) (true) +:test ((mod3 (+3)) =? (+0)) (true) +:test ((mod3 (+4)) =? (+1)) (true) +:test ((mod3 (+5)) =? (+2)) (true) +:test ((mod3 (+6)) =? (+0)) (true) +:test ((mod3 (+7)) =? (+1)) (true) +:test ((mod3 (+8)) =? (+2)) (true) +:test ((mod3 (+9)) =? (+0)) (true) + +main [[0]] |