Hacker News new | past | comments | ask | show | jobs | submit login

IO and side effects have aboslutely nothing to do with referential transparency. A referentially transparent expression is one whose subterms can be replaced with other subterms having the same meaning (reference) without changing the meaning of the expression. Hence, the expression -- a piece of syntax -- is transparent to its reference (denotation, or meaning). Change any piece with another with the same meaning, and the overall meaning is the same.

For example, Java is a referentially transparent language. Suppose we have:

    int x;
    int f() { x++; return 3; }
    int g() { x++; return 3; }
Then g and f have the same meaning, and in any Java expression, they are interchangeable (the fact they have side-effects is totally irrelevant). This is not true for Clojure and Haskell (template Haskell), which are not referentially transparent, because, e.g.

    (defn f [] 3)
    (defn f [] 3)
    (defmacro foo [x] (str x))
Then (foo f) and (foo g) mean something very different, even though f and g have the same reference, hence the expression (foo ...) is not transparent to its subterms' references, but rather their syntax obscures them.

When some FP people say "referential transparency" they actually mean something else altogether. They mean that the meaning of a subroutine application that yields the value 3 is indistinguishable from the value 3. This is, indeed, not true in imperative languages like Java and Clojure, but this is called "value semantics" -- i.e. the meaning of any expression is just a value in the language -- or simply, being pure functional. Then why do they call it "referential transparency"? This has to do with social dynamics in the FP community that is eager to use mathematical-sounding terms but the people don't usually have the requisite mathematical understanding, so like in a game of telephone those terms are quickly used incorrectly and drift away from their correct meaning.

Natural language (see example in the link I posted in my previous comment), programming languages with macros and modal logics are not referentially transparent, because referential opacity adds more power to a language (Lisp can express computations that the lambda calculus cannot, thanks to macros). That FP people (who often rely on referential opacity) say referential transparency is a good thing is also a result of a compulsion in that community to take neutral mathematical definitions and assign them moral values. Referential trasnparency has some properties, some of them can be helpful in some circumstances and some can be harmful in other circumstances. In general, however, it is not a particularly important property one way or the other.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: