summaryrefslogtreecommitdiff
path: root/revtwice.icl
diff options
context:
space:
mode:
authorCamil Staps2016-10-11 12:29:53 +0000
committerCamil Staps2016-10-11 12:29:53 +0000
commitdac20e1e41bbe12b178870d368e7fc56fc12815b (patch)
tree8250447fc2ff0716c87aaa537bfeb0f5640532c2 /revtwice.icl
parentInitial commit (diff)
Added simple examples
Diffstat (limited to 'revtwice.icl')
-rw-r--r--revtwice.icl26
1 files changed, 26 insertions, 0 deletions
diff --git a/revtwice.icl b/revtwice.icl
new file mode 100644
index 0000000..e5186d4
--- /dev/null
+++ b/revtwice.icl
@@ -0,0 +1,26 @@
+module revtwice
+
+/*
+Reversing a list a number of times using Twice.
+
+Increase stack size to 1m and heap size to 2m to run this program.
+
+A list containing 25 integers is reversed 65536 times by means
+of four applications of the higher order function Twice.
+*/
+
+import StdInt, StdEnum
+
+Revv:: [Int] -> [Int]
+Revv l = Rev l []
+where
+ Rev::[Int] [Int] -> [Int]
+ Rev [x:r] list = Rev r [x : list]
+ Rev [] list = list
+
+Twice::(x -> x) x -> x
+Twice f x = f (f x)
+
+Start::[Int]
+Start = Twice Twice Twice Twice Revv [1..25]
+