-map(f, l){
- if(isEmpty(l)){
- return [];
- } else {
- return f(l.hd) : map(f, l.tl);
- }
-}
-
-foldr(f, acc, l){
- if(isEmpty(l)){
- return acc;
- } else {
- return foldr(f, f(acc, l.hd), l.tl);
- }
-}
+//map(f, l){
+// if(isEmpty(l)){
+// return [];
+// } else {
+// return f(l.hd) : map(f, l.tl);
+// }
+//}
+//
+//foldr(f, acc, l){
+// if(isEmpty(l)){
+// return acc;
+// } else {
+// return foldr(f, f(acc, l.hd), l.tl);
+// }
+//}
+//
+//filter(f, l){
+// if(isEmpty(l)){
+// return [];
+// } else {
+// if(f(l.hd)){
+// return filter(f, l.tl);
+// } else {
+// return l.hd : filter(f, l.tl);
+// }
+// }
+//}
+//
+//intList(x){
+// if(x <= 1){
+// return [x];
+// } else {
+// return x : intList(x-1);
+// }
+//}
-filter(f, l){
- if(isEmpty(l)){
- return [];
- } else {
- if(f(l.hd)){
- return filter(f, l.tl);
- } else {
- return l.hd : filter(f, l.tl);
- }
- }
+plus(x, y){
+ return x + y;
}
-intList(x){
- [Int] l = [];
- Int a = 1;
- while(a <= x){
- l = a : l;
- a = a + 1;
- }
- return l;
+apply(f, x){
+ return f(x);
}
main(){
- print("faculty of 5 is: ", foldr(\x y->x*y, 1, intList(5)));
- print("sum of 1..5 is: ", foldr(\x y->x+y, 0, intList(5)));
- print("filter evens from 0..12 is: ");
- print("sum of 0..12 but only the evens: ",
- foldr(\x y->x+y, 0, filter(\x->x%2 == 0, intList(12))));
+// print("faculty of 5 is: ", foldr(\x y->x*y, 1, intList(5)));
+// print("sum of 1..5 is: ", foldr(\x y->x+y, 0, intList(5)));
+// print("filter evens from 0..12 is: ");
+// print("sum of 0..12 but only the evens: ",
+// foldr(\x y->x+y, 0, filter(\x->x%2 == 0, intList(12))));
+
+ var a = plus(3);
+ var b = apply(a);
+ var c = apply(b);
+ var d = apply(c);
+ var e = apply(d);
+ var f = apply(e);
+ var g = apply(f);
+ var h = apply(g);
+ var i = apply(h);
+ var j = apply(i);
+ var k = apply(j);
+ var l = apply(k);
+ var m = apply(l);
+ var n = apply(m);
+ var o = apply(n);
+ var p = apply(o);
+ var q = apply(p);
+ var r = apply(q);
+ var s = apply(r);
+ var t = apply(s);
+ var u = apply(t);
+ var v = apply(u);
+ var w = apply(v);
+ var x = apply(w);
+ var y = apply(x);
+ var z = apply(y);
+
+ print("3+5=", z(5));
}
}
main(){
- var plus = hyper(2);
- var times = hyper(3);
- var power = hyper(4);
- var arrow = hyper(5);
-
- print("2 + 4 = ", plus(2, 4));
- print("2 * 4 = ", times(2, 4));
- print("2 ^ 4 = ", power(2, 4));
- print("3 | 2 = ", arrow(3, 2));
+ print("s(3)=", hyper(0, 3, 3));
+ print("3+3=", hyper(1, 3, 3));
+ print("3*3=", hyper(2, 3, 3));
+ print("3^4=", hyper(3, 3, 4));
+ print("2|3=", hyper(4, 2, 3));
}