[Haskell-cafe] "show" for functional types
Neil Mitchell
ndmitchell at gmail.com
Fri Mar 31 20:11:20 EST 2006
Hi,
First, its useful to define referential transparency.
In Haskell, if you have a definition
f = not
Then this means that anywhere you see f, you can replace it with not.
For example
"f True" and "not True" are the same, this is referentially transparent.
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.
Hence, you have now broken referential transparency.
So you can't show these two functions differently, so what can you do
instead? You can just give up and show all functions the same
instance Show (a -> b) where
show x = "<function>"
This is the constant definition of show mentioned.
Thanks
Neil
On 4/1/06, Greg Buchholz <haskell at sleepingsquirrel.org> wrote:
> In section 5 of _Fun with Phantom Types_, Hinze states...
>
> "Let us move on to one of the miracles of theoretical computer
> science. In Haskell, one cannot show values of functional types. For
> reasons of computability, there is no systematic way of showing
> functions and any ad-hoc approach would destroy referential transparency
> (except if show were a constant function). For instance, if show yielded
> the text of a function definition, we could distinguish, say, quick sort
> from merge sort. Substituting one for the other could then possibly
> change the meaning of a program."
>
> ...I guess I'm not understanding what that means. Would there be some
> sort of contradiction that arises when trying to evaluate "show (show)"
> or somesuch? Can anyone point me in the direction of information that
> tries to explain why this is? I'm at a loss as to what search terms to
> use.
>
> Thanks,
>
> Greg Buchholz
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list