on bf4e535 help sign in
Idris-dev/iif/testmap.iif
30 lines 808 B history raw
1data Nil 0
2data Cons 2
4fun twice(f, x) = f(f(x))
6fun map(f, xs) = case xs of {
7 Nil => Nil
8 | Cons(y, ys) => Cons(f(y), map(f, ys))
9 }
11fun dumpList(xs) = case xs of {
12 Nil => "END"
13 | Cons(y, ys) => %IntString(y) ++ ", " ++ dumpList(ys)
14 }
16fun countFrom(x) = Cons(x, countFrom@(x+1))
18fun take(n, xs) = case n of {
19 0 => Nil
20 | _ => case xs of {
21 Nil => Nil
22 | Cons(y, ys) => Cons(y, take(n-1, ys))
23 }
24 }
26fun double(x) = x + x
28fun main() = let mult = 2 in
29 %WriteString(dumpList(map(twice(\ x => x*mult), take(1010, countFrom(10)))))