From 39410dcec77d33c95eedd4480a3121cf352bcf1b Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 21 Apr 2018 11:12:06 +0200 Subject: Add fixpoint peano addition example --- examples/peano.fusp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/peano.fusp diff --git a/examples/peano.fusp b/examples/peano.fusp new file mode 100644 index 0000000..b8d1cb8 --- /dev/null +++ b/examples/peano.fusp @@ -0,0 +1,21 @@ +import bool; +import int; + +fix f = fixb f (fixb f); +fixb f x = f (x x); + +main = peano_to_int (fix padd (int_to_peano 5) (int_to_peano 10)); + +pzero (0,_) = 1; +pzero _ = 0; + +pinc n = (1,n); +pdec (1,n) = n; + +peano_to_int (0,_) = 0; +peano_to_int (1,n) = add 1 (peano_to_int n); + +int_to_peano 0 = (0,0); +int_to_peano n = (1,int_to_peano (sub 1 n)); + +padd a m n = if (pzero n) m (pinc (a m (pdec n))); -- cgit v1.2.3