This is quite a nice extensible approach to the FizzBuzz problem as adding 7-Bazz is as easy as adding another rule.
Other Uses Of Recursion
The examples we've used are necessarily simple to concentrate on tail call optimisation using an accumulator but what would we really use recursion for in a real application? Recursion is great for handling hierarchical data like the file system or XML, converting between flat data and hierarchies and for event loops or loops where there is no defined finish.
Further Reading
As always, Scott Wlaschin's excellent site has many posts on the topic (https://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3b/#series-toc).
Conclusion
In this post we have had a look at recursion in F#. In particular, we have looked at how to use accumulators with tail call optimisation to make recursion more efficient.
This may be the last post in this series. Either way, look out for a new series on creating websites and APIs in F# with Giraffe - Coming soon!
If you have any comments on this series of posts or suggestions for new ones, send me a tweet (@ijrussell) and let me know.
Introduction to Functional Programming in F#