Using recursion
Recursion is a key technique in FP, to the degree that some languages do not provide for iterations or loops, and work exclusively with recursion (Haskell, which we already mentioned, is a prime example of that). A fundamental fact of computer science is that whatever you can do with recursion, you can do with iteration (loops), and vice versa. The key concept is that there are many algorithms whose definition is far easier if you work recursively. On the other hand, recursion is not always taught, and many programmers, even after knowing about it, prefer not to use it. Therefore, in this section, we shall see several examples of recursive thinking so that you can adapt it for your functional coding.
A typical, oft-quoted, and very old computer joke!
Dictionary definition: recursion: (n) see recursion
But what is recursion? There are many ways to define what recursion is, but the simplest one I’ve seen runs along the lines of a function calling itself...