Referential transparency (computer science)

The Referential transparency means that the value of an expression depends to a source only from its surroundings and not from the time of its evaluation. This is an important property of the declarative programming paradigm.

In mathematics is that one and the same variable at different points of its scope always has the same value. This does not apply in imperative programming languages ​​, as the program semantics (eg final result) of an implicit state (eg memory capacity ) depends.

X = x 1 Formal analyzes this equation is a permanent statement, which means there is no x that makes the equation true. Nevertheless, this line is possible in imperative programming languages, but there is not understood as an equation, but as an assignment: Depending on what is in the memory cell for x, the right side is calculated and the result is assigned the left.

But if you want the program properties mathematically prove (for example, the program really delivers what it is ), then these side effects may not occur. In declarative programming, however, applies the principle of referential transparency and as a consequence, the substitution principle. Then an expression can always be replaced by another of equal value without this having an impact on the program semantics. The goal of such program transformations is the replacement of cumbersome, due simply to be calculated expressions.

However, the principle of referential transparency also raises problems. So the simple reading of a character entered using the keyboard is not directly possible; such a function - such as getchar in C - is not allowed. Each time, the return value would be dependent on the user's input. This incur communication problems with the environment.

Thus, for example in Haskell actions that can interact with the environment, described as values ​​of the data type IO. Using special operators, complex descriptions can be constructed from elementary action descriptions. Each Haskell program defines a variable main, the value of which is an action description of the entire program. Actions can be executed by their description is embedded in the value of main.

  • Programming
675919
de