--- /dev/null
+reverse (list) :: [Int] -> [Int] {
+ var accu = [];
+ while (! isEmpty (list)) {
+ accu = list . hd : accu;
+ list = list . tl;
+ }
+ return accu;
+}
+
+coPrimeWith (elem, list) :: Int -> [Int] -> Bool {
+ if (isEmpty(list)) {
+ return True;
+ } else {
+ if (elem % list.hd == 0) {
+ return False;
+ } else {
+ return coPrimeWith(elem, list.tl);
+ }
+ }
+}
+
+factorize (n) :: Int -> [Int] {
+ var primes = [];
+ var i = 2;
+ while (i < n) {
+ if (n % i == 0 && coPrimeWith(i, primes)) {
+ print("Found prime: ", i);
+ primes = i : primes;
+ }
+ i = i + 1;
+ }
+ return primes;
+}
+
+print_list_inner (list) :: [Int] -> Void {
+ if (isEmpty(list)) {
+ return;
+ } else {
+ print(list.hd);
+ if (!isEmpty(list.tl)) {
+ print(',');
+ print(' ');
+ }
+ return print_list_inner(list.tl);
+ }
+}
+
+print_list (list) :: [Int] -> Void {
+ print('[');
+ print_list_inner(list);
+ print(']');
+ print('
+');
+ return;
+}
+
+main (){
+ //var number = 692963517;
+ var number = 12000;
+ var result = reverse(factorize(number));
+ print_list(result);
+ return;
+}
\ No newline at end of file
}
}
+giveF(){
+ return (\x->x+1);
+}
+
+
+
main(){
var x = 5;
+
+ var f = giveF();
+
+ var plus = \x y->x+y;
+
+ var g = map(plus, [1,2,3]);
+ var is = map(\f->f(1), g);
+
+ //print("is.hd", is.hd);
+
+ print("f(4) = ", f(4));
+
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: ",