2 ms·
Alternatively, making use of laziness and recursive definitions: fibonacci n = fibs !! n fibs = 1:1:zipWith (+) fibs (tail fibs)
by gamegoblin 12y ago
Alternatively, making use of laziness and recursive definitions:
fibonacci n = fibs !! n
fibs = 1:1:zipWith (+) fibs (tail fibs)
- Pitarou 12y agoYour version is certainly pretty, and it's based on an insight into the nature of the fibonacci series But the value of co-recursion is that you don't need that insight. When you expand out the definitions of `tail`, `!!` and `zipWith`, your code turns out to be the same as mine[1], so I consider that a big win for co-recursion. [1]: At least I think it does.