
29 Nov
2001
29 Nov
'01
3:25 p.m.
Then I tried:
sfibac :: IntPos -> (IntPos,IntPos) -> (IntPos,IntPos) sfibac n (a,b)
| n == 0 = (a,b) | otherwise = sfibac (n-1) (b, (+b) $! a)
I'm sorry I meant:
sfibac :: IntPos -> (IntPos,IntPos) -> (IntPos,IntPos) sfibac n (a,b)
| n == 0 = (a,b) | otherwise = sfibac (n-1) (b, (a+) $! b)
otherwise the reductions would be wrong
fibac: sfibac 4 (a, b) -> sfibac 3 (b, a+b) -> sfibac 2 (c, b+c) -> sfibac 1 (d, c+d) -> sfibac 0 (e, d+e)
In fact I would expect that using ((a+) $! b) would be better than (b, (+b) $! a), but the 1st seemed to be the worst in terms of both speed and stack space problems. J.A.