[Haskell-cafe] "show" for functional types
Christopher Brown
cmb21 at kent.ac.uk
Sat Apr 1 05:22:15 EST 2006
>
> Here is another example. Consider two functions f and g which,
> given the same inputs, always return the same outputs as each other
> such as:
>
> f x = x + 2
> g x = x + 1 + 1
>
> Now since f and g compute the same results for the same inputs,
> anywhere in a program that you can use f you could just replace f
> by g and the observable behaviour of the program would be
> completely unaffected. This is what referential transparency means.
>
Another example:
In haskell the following is true:
f x + g x == g x + f x
Pure functions in Haskell do not have side effects, so for the same
inputs they always give back the same output. This is referential
transparency.
In a language such as C, which does not have referential
transparency, the functions f and g may change x by a side effect and
therefore:
f x + g x /= g x + f x
In C (or a language with side effects).
Cheers,
Chris.
Christopher Brown
PhD Student, University of Kent.
http://www.cs.kent.ac.uk/people/rpg/cmb21/
cmb21 at kent.ac.uk
More information about the Haskell-Cafe
mailing list