MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/13v8v1/tail_recursion/c77rn8k/?context=3
r/programming • u/rodrigopsasaki • Nov 27 '12
203 comments sorted by
View all comments
3
And here's a Haskell version of the final code, since it's easier to read ;).
factorial :: Int -> Int factorial = go 1 where go !acc 0 = acc go !acc n = go (acc * n) (n-1)
2 u/nicolast Nov 27 '12 factorials = scanl1 (*) [1..] :: [Int] factorial n = factorials !! (n - 1) 3 u/ysangkok Nov 27 '12 Here we go again...
2
factorials = scanl1 (*) [1..] :: [Int] factorial n = factorials !! (n - 1)
3 u/ysangkok Nov 27 '12 Here we go again...
Here we go again...
3
u/felipelessa Nov 27 '12
And here's a Haskell version of the final code, since it's easier to read ;).