3 ms·
Have always appreciated Haskell's tail-recursive one fib = (fibs !!) where fibs = 0 : 1 : zipWith (+) fibs (tail fibs) main = putStrLn $ show $
by ngcazz 2y ago
Have always appreciated Haskell's tail-recursive one
fib = (fibs !!)
where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
main = putStrLn $ show $ fib 1000
- bmacho 2y agoYou probably just jest, either way fibs is not tail recursive [0], since its returning value is a list constructor, and not a call to itself. [0] : https://stackoverflow.com/questions/33923/what-is-tail-recursion https://stackoverflow.com/questions/33923/what-is-tail-recur...
- ngcazz 2y agoNo jest, I just recalled this formulation incorrectly as being tail-recursive. Thanks for reminding me.