aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2016-10-04 20:16:56 +0200
committerCamil Staps2016-10-04 20:16:56 +0200
commit2cd524e55f4d3057fe82db119541b1b5284629dc (patch)
tree5ed4dc27682c39a9c3f4c1e3a9f731c02a32b63b
parentDebug graph readability improvements (diff)
Examples
-rw-r--r--examples/bool.fusp2
-rw-r--r--examples/fold.fusp2
-rw-r--r--examples/int.fusp10
-rw-r--r--examples/list.fusp20
-rw-r--r--examples/palindrome.fusp9
5 files changed, 42 insertions, 1 deletions
diff --git a/examples/bool.fusp b/examples/bool.fusp
new file mode 100644
index 0000000..2676c6b
--- /dev/null
+++ b/examples/bool.fusp
@@ -0,0 +1,2 @@
+if 0 _ y = y;
+if 1 x _ = x;
diff --git a/examples/fold.fusp b/examples/fold.fusp
index 0d38cdc..a68d671 100644
--- a/examples/fold.fusp
+++ b/examples/fold.fusp
@@ -11,4 +11,4 @@ faclist n = [n:faclist (sub 1 n)];
fac n = prod (faclist n);
-main = fac 12;
+main = fac 4;
diff --git a/examples/int.fusp b/examples/int.fusp
new file mode 100644
index 0000000..fe1e32d
--- /dev/null
+++ b/examples/int.fusp
@@ -0,0 +1,10 @@
+sub a b = code sub a b;
+add a b = code add a b;
+mul a b = code mul a b;
+
+eq a b = code eq a b;
+ge a b = code ge a b;
+gt a b = code gt a b;
+le a b = code le a b;
+lt a b = code lt a b;
+ne a b = code ne a b;
diff --git a/examples/list.fusp b/examples/list.fusp
index 2fce492..de3059e 100644
--- a/examples/list.fusp
+++ b/examples/list.fusp
@@ -1,3 +1,5 @@
+import int;
+
append [] ys = ys;
append [x:xs] ys = [x:append xs ys];
@@ -9,3 +11,21 @@ isEmpty _ = 0;
hd [x:_] = x;
tl [_:x] = x;
+
+last [x:[]] = x;
+last [_:xs] = last xs;
+
+init [] = [];
+init [x:[]] = [];
+init [x:xs] = [x:init xs];
+
+length_tl i [] = i;
+length_tl i [_:xs] = length_tl (add 1 i) xs;
+
+length xs = length_tl 0 xs;
+
+repeat 0 _ = [];
+repeat n x = [x:repeat (sub 1 n) x];
+
+map f [] = [];
+map f [x:xs] = [f x:map f xs];
diff --git a/examples/palindrome.fusp b/examples/palindrome.fusp
new file mode 100644
index 0000000..d2c6eba
--- /dev/null
+++ b/examples/palindrome.fusp
@@ -0,0 +1,9 @@
+import int;
+import list;
+import bool;
+
+is_palindrome [] = 1;
+is_palindrome [_:[]] = 1;
+is_palindrome [x:xs] = if (eq x (last xs)) (is_palindrome (init xs)) 0;
+
+main = is_palindrome [0:[42:[37:[42:[0:[]]]]]];