Haskell for C programmers example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
int * fibArray(int n) {
int * fibs;
fibs = (int *)malloc((sizeof int) * n);
for (i = 0; i < n; i++) {
fibs[i] = a;
temp = a + b;
a = b;
b = temp;
}
return fibs;
}
--------------------------------------------------------
fibs :: [Int]
fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]