Tenth. Efficiency of data structure
This chapter describes
optimizing and improving recursive functions
Use tail recursion (tail-recursion) and continuous (continuations)
Efficient use of lists and arrays
So far, the functional approach that we've used in this book has recursive and functional data structures, such as immutable lists. The simplest code we can write is to use the basic F # collection type (list) to express our intentions directly. In many cases, this approach is appropriate, but when it comes to working with large datasets, it is "obvious" that code can sometimes cause performance problems. In this chapter, we will learn some ways to write code, regardless of the size of the input data, and the performance of the processing data function is optimized. We will still try to keep the code as readable as possible.
If you have developed any long-running programs, it is almost certain that a program that is written usually causes a stack overflow exception. In function programming, it is possible that this error is due to the immature recursive function, so we will explore several ways to solve the problem that can cause this error when dealing with large amounts of data. This is the topic we started with, and we'll go back to that topic at the end of this chapter.
In the middle of the discussion about recursion, we focus on the functional list and the array. Working with functional lists, the most important way to understand their principles is that they can be used effectively; F # also supports arrays and, in some cases, provides better performance. Although the array is primarily an imperative data type, you will find that we can also use it in a very functional way.
Tenth. Efficiency of data structure