|
|
last edited 8 years ago by test1 |
1 2 | ||
Editor: test1
Time: 2016/07/29 18:23:18 GMT+0 |
||
Note: |
changed: - In pure functional programing there are no variables, there are only values. Values are immutable and logically exist "forever" from creation. Program creates new values from old ones, typically using functions. Traditional loops are of no use in pure functional programming because repeating computation will produce the same value. Instead, recursion can produce effects equivalent to traditional loops. There are practical problems with pure functional programming. First, since values exists forever eventually they will exhaust all available memory. This is resolved by noting that some values are unreachable: there is no way to reference them in further computation. Consequently memory used by unreachable values can be freed and reused for new values. This is called garbage collection. Without garbage collection functional programming would be of limited use. Second, interesting programs interact with environment, for example draw graphs on the screen. Such activities mean that program is no longer pure functional, but can be included in way compatible with functional style. Third, some computations, like graph traversal became complicated without ability to change values. So pure functional programming is frequently regarded as doing things with unnecessary restrictions. However, to deal with restrictions functional programming developed new style which in many cases leads to short and efficient programs.
In pure functional programing there are no variables, there are only values. Values are immutable and logically exist "forever" from creation. Program creates new values from old ones, typically using functions. Traditional loops are of no use in pure functional programming because repeating computation will produce the same value. Instead, recursion can produce effects equivalent to traditional loops. There are practical problems with pure functional programming. First, since values exists forever eventually they will exhaust all available memory. This is resolved by noting that some values are unreachable: there is no way to reference them in further computation. Consequently memory used by unreachable values can be freed and reused for new values. This is called garbage collection. Without garbage collection functional programming would be of limited use. Second, interesting programs interact with environment, for example draw graphs on the screen. Such activities mean that program is no longer pure functional, but can be included in way compatible with functional style. Third, some computations, like graph traversal became complicated without ability to change values. So pure functional programming is frequently regarded as doing things with unnecessary restrictions. However, to deal with restrictions functional programming developed new style which in many cases leads to short and efficient programs.