[<<][compsci][>>][..]
Fri Jan 14 14:52:28 EST 2011

Understanding Referential Transparency

If you look at the definition of Referential Transparency[1] (RT)
which says that a computation can always be replaced by its value, it
seems to be relatively straightforward.

What I found really hard to understand is why this does away with
object identity.  The `eq?' function in Scheme which compares pointers
has no place in Haskell, because it has a result that depends on
whether its arguments come from the same evaluation (value copied) or
not (value obtained by running the same computation twice).

In essence this means that a value does not have an implicit, unique
name.  A value is just a value and nothing more.  To name values, a
function needs to be defined that associates a name to a value or the
other way around.

Of course, pointer comparison does show up in the Haskell trenches,
because it is too useful for implementing some low-level forms of
memoization that would otherwise lead to exponential complexity.  See
makeStableName[3].  It soils your code with the IO monad though,
unless you go down the bumpy road of unsafePerformIO[4].


[1] http://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29
[2] http://stackoverflow.com/questions/1717553/pointer-equality-in-haskell
[3] http://www.haskell.org/ghc/docs/7.0.1/html/libraries/base-4.3.0.0/System-Mem-StableName.html
[4] http://www.mail-archive.com/haskell-cafe@haskell.org/msg52544.html



[Reply][About]
[<<][compsci][>>][..]