3 ms·
> Referential transparency implies that we can everywhere replace an expression with any reduction of it I'm aware, but that's too strong a requirement. I want
by catnaroek 10y ago
> Referential transparency implies that we can everywhere replace an expression with any reduction of it
I'm aware, but that's too strong a requirement. I wanted my definition to capture the bare minimum necessary to make it pleasant to write functional programs. The basic idea is “functional programming is designing your programs in terms of mathematical functions whenever possible (not always!)”, not “functional programming is requiring an embedded IO DSL to do anything effectful”. (But don't take this as a dismissal of Haskell. While I do have complaints against it, effect segregation isn't one of them.)
> but because the return value of this function can change even when its arguments don't, this is not true in Javascript.
That's okay. A procedure that returns the system date will never be referentially transparent, yet such a procedure is a necessity in any programming language.
My beef is actually with the fact JavaScript doesn't have compound values: https://news.ycombinator.com/item?id=12191119 https://news.ycombinator.com/item?id=12191119 . Since compound entities (whether values or mutable objects) are a necessity in practical programming, the harsh reality is that JavaScript programmers have to use mutable objects whether they want it or not.
- solidsnack9000 10y ago> That's okay. A procedure that returns the system date will never be referentially transparent, yet such a procedure is a necessity in any programming language. As long as it accepts a Universe or State parameter, a system time function is referentially transparent. This is rather like how every query in a database can be seen as implicitly depending on a transaction ID parameter. One intuition that falls out of the Church-Turing thesis is that there is no routine in C, Pascal, &c that has no referentially transparent equivalent.
- catnaroek 10y ago> As long as it accepts a Universe or State parameter, a system time function is referentially transparent. Which begs the question - where do you get that Universe parameter from? Note that getting a single Universe parameter at the beginning of the program is of no use, because then you couldn't query the system date right now. You could only query the system date at the moment the program started. You can't completely get rid of non-referentially transparent procedures in a general-purpose programming language. What you can do, at most, is banish them to a special sublanguage, like Haskell does. > the Church-Turing thesis The Church-Turing thesis is a statement about computable functions, but a procedure that returns the system date clearly doesn't compute a mathematical function.
- solidsnack9000 10y ago> ...getting a single Universe parameter at the beginning of the program is of no use, because then you couldn't query the system date right now. This is like saying, "...getting a single input at the beginning of the program is of no use..." but see below. > The Church-Turing thesis is a statement about computable functions... It is a statement about what is "computable", which is the alpha and the omega of what computers can do. If there is a Turing model for a particular "computation" there is a Lambda Calculus model for it. A program that returns the system date operates on the machine state. You can treat this as "read from the tape" in the Turing sense or as input in the Lambda Calculus sense. The "output" can be seen as one of: * A tape where the system states has been updated (since we took some steps, we updated the CPU counter, handled some interrupts, &c) and the system time has been written to a special place on the tape so the next computation can find it. * A tuple of a new system state and the time value (picked out, again, for our convenience). If we imagine the world "as a computer" then it is natural to compute a later state of the world as a function of the previous state. This approach actually works well in practice and it is not coincidental that this approach works with computers, since it is deeply tied into how they work. Per Heraclitus, we never set foot in the same river twice. Treating the State or Universe as non-comparable captures this idea.
- catnaroek 10y ago> It is a statement about what is "computable", which is the alpha and the omega of what computers can do. The Church-Turing thesis is about what functions are computable. > A program that returns the system date operates on the machine state. You can treat this as "read from the tape" in the Turing sense or as input in the Lambda Calculus sense. Are you saying that the input tape may contain the later time at which a program will query the system's date? That seems like a physical impossibility to me. > If we imagine the world "as a computer" then it is natural to compute a later state of the world as a function of the previous state. The fundamental deficiency of this model is that it assumes you can put the entire world inside your program, and then get an entire new world as result. It utterly fails to take concurrency into consideration.