UP | HOME

Referential Transparency

When functions are pure, i.e. have no side effects, any time the function is mentioned in a program, we can replace it with the function body and the program behavior will not change.

1 Small example

Consider a function f with side-effects. Maybe f returns a number, but also prints something to the console. Now, consider an a variable assignment a = f(x). If a is never used, then this is dead code that should be removed. But because f is side-effects, we may end up altering the behavior of the program.

In contrast, if f had no side effects, we could perform removal automatically.

2 Related concepts

3 Useful links

Created: 2021-09-14 Tue 21:44