S
Sean O'Dell
Sean O'Dell said:
One of the benefits of functional languages is the ability to do
algebraic-like manipulations of the source code ... kinda like provably
correct refactorings. For example, given X=12, within the scope of X I
can replace all occurances of X with the value 12 (or the reverse, replace
all occurances of 12 with X). If X is sometimes 12 and sometimes 13, then
the substitution is no longer valid anywhere in the scope of X. That is
why even local variables are immutable in a "pure" functional language.
But this is more of an implementation feature. Tail recursion optimization
and currying are features, not really part of the true definition of a
functional language. You could make C's variables totally immutable and
pre-process C code in the same way. It's a feature that's easy to do with
functional languages, but I don't think truly at the heart of them. Having
mutable, local variables in a functional language disables such features, but
the language is still a functional one.
Function being defined as an operation that returns the same result given
the same input, right? Operators in functional languages are functions in
this sense. The difference is a matter of syntax, not semantics. E.g.
1+2 is allowed in a functional language. The binary operator + is treated
as a two argument function.
Yes, precisely what I meant.
Sean O'Dell