A functional programming style is a description of what you want, not how to get it. i.e.: instead of creating a for loop with an iterator variable and going through an array that does something in each cell, you should say that the equivalent of “this label refers to the version of this array where this function was executed on all elements”.
Functional programming moves more basic programming ideas into the compiler, such as list comprehension and caching.
The biggest advantage of functional programming is brevity, because code can be shorter. A functional program does not create an iterator variable as the center of the loop, so this and other types of overhead are excluded from your code.
Another important advantage is concurrency, which is easier to do with functional programming, because the compiler performs most of the operations that required manual configuration of state variables (for example, an iterator in a loop).
Some performance benefits can also be seen in the context of a single processor, depending on how the program is written, since most functional languages and extensions support lazy evaluation. In Haskell, you can say that "this label represents an array containing all even numbers." Such an array is infinitely large, but you can request the 100,000th element of this array at any time without knowing - when you initialize the array - exactly what you need is the biggest value. The value will be calculated only when you need it, and no further.
Chris Wenham Sep 24 '08 at 16:14 2008-09-24 16:14
source share