3 ms·
Pure FP doesn't have variables. It has bindings.
by TylerE 13y ago
Pure FP doesn't have variables. It has bindings.
- groovy2shoes 13y agoFunction parameters are variables even in pure FP. If your definition of variable requires assignment, then even mathematics doesn't have variables.
- alipang 13y agoWhat do the bindings bind then? So, no, even in pure functions like f x = x + 1 x is a bound variable. It doesn't 'vary' in the sense that the value it refers to can be mutated, as in a imperative language, but it varies between calls to the function f.
- TylerE 13y agoIt is rebound. It is improper to call it a "variable" because in any given lifetime, it's value cannot vary. That's the point. It is possible to create a new binding with the same name, but any code holding on to the old instance keeps the old value. Subtle but important difference.
- mbrock 13y agoYou're simply wrong. That's not how the term "variable" works. From http://en.wikipedia.org/wiki/Variable_(mathematics) http://en.wikipedia.org/wiki/Variable_(mathematics): "Varying, in the context of mathematical variables, does not mean change in the course of time, but rather dependence on the context in which the variable is used."
- tel 13y agoWhile I agree with your philosophy of vocabulary here, I've read the Harper article too, it's valuable to state directly that everyone knows there's the _(Programming) article too and is simply disagreeing that its a "good" way to use the term. Anyone who isn't familiar with the distinction in terminology ought to consider what things a programming variable represents that a mathematics variable does not..
- Symmetry 13y agoFrom http://en.wikipedia.org/wiki/Variable_%28programming%29 http://en.wikipedia.org/wiki/Variable_%28programming%29 "The identifier in computer source code can be bound to a value during run time, and the value of the variable may thus change during the course of program execution. Variables in programming may not directly correspond to the concept of variables in mathematics."
- mbrock 13y agoIt's wrong that it's "improper" to use the term "variable" for Haskell variables, since it is an established usage. This usage of "variable" occurs in the very first paragraph of Church's first paper on lambda calculus from 1931 in the motivation for the whole project!
- iopq 13y agoMath doesn't have vars, only vals
- mbrock 13y agoThat's a rather strange assertion, if you mean "variables" and "values." Math distinguishes between variables and values. Variables have different values. Values can be bound to variables. Sometimes we do math with mostly variables and few values -- that's called algebra.
- marssaxman 13y agoThis seems like splitting hairs.
- TylerE 13y agoIt's not. Referential transparency and immutability (or lack thereof) is a big deal, especially when it comes to multi-threaded code.
- kyllo 13y agoWhen combined with lexically scoped closures, if you try to shadow your value bindings in a functional language and expect it to work the same way as mutating a variable does in an imperative language, you're in for a surprise.
- marssaxman 13y agoSure, you have to restrict the scope in which rebinding is legal, but I don't see how it's fundamentally any different than the use of a phi-node in SSA form.
- kyllo 13y agoHere's an SML example: - val a = 1; val a = 1 : int - fun f() = a; val f = fn : unit -> int - f(); val it = 1 : int - val a = 2; val a = 2 : int - f(); val it = 1 : int // a is still bound to 1 as far as f() is concerned Now in Javascript: > var a = 1; undefined > function f(){return a}; undefined > f(); 1 > a = 2; 2 > f(); 2 > If you bind a val, then you define a function that references that val, then you later shadow the val binding, then call the function again, the function still sees the earlier val binding, because it's a closure of the environment at the point where the function was defined, not at the point where it was called. This is unlike variable assignment in imperative languages.