-//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);
-// }
-//}
-
-plus3(x, y, z){
- return x + y;
+map(f, l){
+ if(isEmpty(l)){
+ return [];
+ } else {
+ return f(l.hd) : map(f, l.tl);
+ }
}
-plus(x, y){
- return x+y;
+foldr(f, acc, l){
+ if(isEmpty(l)){
+ return acc;
+ } else {
+ return foldr(f, f(acc, l.hd), l.tl);
+ }
}
-apply(f, x){
- return f(x);
+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);
+ }
+ }
}
-ap2(f, g, x){
- return f(g(x));
+intList(x){
+ if(x <= 1){
+ return [x];
+ } else {
+ return x : intList(x-1);
+ }
}
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))));
-
- var a = plus3;
- var b = a(1);
- var c = b(2);
- var d = c(3);
+ var x = 5;
+ 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("sum of 0..12 but only the evens: ",
+ foldr(\x y->x+y, 0, filter(\x->x%2 == 0, intList(12))));
}
return i*m;
}
-//printList(p, l) :: (a -> Void) -> [a] -> Void {
-printList(p, l) {
+printList(p, l) :: (a -> Void) -> [a] -> Void {
print('[');
if(!isEmpty(l)){
p(l.hd);
var num = "-1234";
printList(printInt, [32, 4, strToInt(num)]);
-// printList(printBool, [True, False, True, True]);
+ printList(printBool, [True, False, True, True]);
}