aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2016-10-16 21:46:51 +0200
committerCamil Staps2016-10-16 21:59:27 +0200
commit88bcec774b782319aa4ce32a39c101568d01925a (patch)
tree0213a083eba76dd9ef177a781ce585e273490934
parentUsage message when no modules are given (diff)
examples
-rw-r--r--examples/hamming.fusp12
-rw-r--r--examples/list.fusp4
-rw-r--r--examples/twice.fusp5
3 files changed, 19 insertions, 2 deletions
diff --git a/examples/hamming.fusp b/examples/hamming.fusp
new file mode 100644
index 0000000..9c6aa48
--- /dev/null
+++ b/examples/hamming.fusp
@@ -0,0 +1,12 @@
+import list;
+import int;
+import bool;
+
+// Taken from the Clean examples: the Hamming function.
+// The first 100 numbers with only 2, 3 and 5 as prime factors.
+
+ham = [1:merge (merge (map (mul 2) ham) (map (mul 3) ham)) (map (mul 5) ham)];
+
+merge [a:b] [c:d] = if (lt a c) [a:merge b [c:d]] (if (eq a c) (merge [a:b] d) [c:merge [a:b] d]);
+
+main = take 100 ham;
diff --git a/examples/list.fusp b/examples/list.fusp
index de3059e..b3f4ea5 100644
--- a/examples/list.fusp
+++ b/examples/list.fusp
@@ -29,3 +29,7 @@ repeat n x = [x:repeat (sub 1 n) x];
map f [] = [];
map f [x:xs] = [f x:map f xs];
+
+take _ [] = [];
+take 0 _ = [];
+take n [x:xs] = [x:take (sub 1 n) xs];
diff --git a/examples/twice.fusp b/examples/twice.fusp
index 8f50b83..a978df8 100644
--- a/examples/twice.fusp
+++ b/examples/twice.fusp
@@ -1,3 +1,4 @@
-mul a b = code mul a b;
+// Set ulimit -s 16384 before running this.
+add a b = code add a b;
twice f x = f (f x);
-main = twice twice twice (mul 2) 1;
+main = twice twice twice twice (add 1) 0;