Google News
logo
Full Stack Developer - Interview Questions
What is referential transparency in functional programming?
A program may have the property of referential transparency if any two expressions in the program that have the same value can be substituted for one another anywhere in the program without changing the result of the program. It is used in functional programming. For example, consider the following code snippet:
count1 = (fun(x) + y) * (fun(x) - z);  
temp = fun(a);  
count2 = temp + y * temp - z;  
The variables count1 and count2 will be equal if the value of fun(x) is not reflected. If the variable count1 is not equal to the variable count2, the referential transparency is violated.
Advertisement