[Haskell-cafe] "show" for functional types

Brian Hulley brianh at metamilk.com
Fri Mar 31 21:45:55 EST 2006

Greg Buchholz wrote:
> Neil Mitchell wrote:
>> Now lets define "super show" which takes a function, and prints its
>> code behind it, so:
>> superShow f = "not"
>> superShow g = "\x -> case ..."
>> now superShow f /= superShow g, so they are no longer referentially
>> transparent.
>    OK.  I'm probably being really dense today, but where did "g" come
> from?  Is this is the internal definition of "not"?  And does this
> loss of referential transparency contaminate the rest of the
> language, or is this superShow just an anomaly?

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.

However, if you allowed a function such as superShow, superShow f == "x + 2" 
and superShow g == "x + 1 + 1" so superShow f /= superShow g thus you could 
no longer just use f and g interchangeably, since these expressions have 
different results.

Thus the existence of superShow would contaminate everything, because if you 
were using a library function for example you would have no way of knowing 
whether the writer of the function had used superShow somewhere deep in its 
implementation ie referential transparency is an all or nothing concept.

Regards, Brian. 

More information about the Haskell-Cafe mailing list