- #1
- 1,231
- 0
If a function written in an imperative style does not set any variables other than local variables, and has access to no input other than its declared inputs (no keyboard input for example), then the function has no side effects. For example
is consistent with functional programming--it has no side effects even though it is written in an imperative style.
Are there functional languages that make use of this--so that individual functions may be written in an imperative style while the whole program is functional in nature? And I don't mean that the language is primarily functional but allows some imperative programming as a special case that you should try to avoid unless absolutely necessary, I mean a language that checks basically imperative functions and verifies they do not have side effects. It seems like this would retain the advantages of functional programming while allowing many things to be implemented more simply.
Code:
Input n
int sum = 0
for i <-- 1 to n
sum <-- sum + i
return sum
Are there functional languages that make use of this--so that individual functions may be written in an imperative style while the whole program is functional in nature? And I don't mean that the language is primarily functional but allows some imperative programming as a special case that you should try to avoid unless absolutely necessary, I mean a language that checks basically imperative functions and verifies they do not have side effects. It seems like this would retain the advantages of functional programming while allowing many things to be implemented more simply.
Last edited: