6

In various discussions of the merits of functional programming, the phrase referential transparency or equational reasoning is often listed.

My question is - are these roughly the same thing? (One being the concept, and the second being the process of applying the concept?

hawkeye
  • 1,199
  • 8
  • 20

1 Answers1

10

Referential transparency is an operational notion: it describes what happens when you evaluate a same piece of code (typically a function) several times, namely, the return value is the same. In particular, the evaluation context can generally be ignored when considering the operational semantics of a referentially transparent language.

Equational reasoning is, well, a way to reason about code: it allows you to replace pieces of code with others without worrying about things like evaluation order or current state. This is usually valid because of referential transparency; in general the value of a given code block is dependent on it's context which prevents replacing a piece of code by another regardless of it's position within another block.

In conclusion, referential transparency is a property of the evaluation semantics and the ability to do equational reasoning is a benefit of this property.

cody
  • 8,184
  • 29
  • 62