[Haskell-cafe] "show" for functional types

Henning Thielemann lemming at henning-thielemann.de
Sat Apr 1 02:43:28 EST 2006

On Fri, 31 Mar 2006, Greg Buchholz 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 find this statement misleading. I do not expect that (2+2::Int) is shown 
as "2+2", but as "4". Analogously I don't expect 'toLower' to be shown as 
"toLower". There are certainly several descriptions of the same value, 
independent from whether the value is a number or a function. So what _is_ 
a function? A function is a set of assignments from arguments to function 
values. That is, a natural way to show a function would be to print all 
assigments. Say

Prelude> toLower
[('A','a'), ('a','a'), ('1', '1'), ...

In principle this instance of 'show' could be even implemented, if there 
would be a function that provides all values of a type.

Another example

Prelude> sort :: [Int] -> [Int]
[([0],[0]), ([0,1],[0,1], ([1,0],[0,1]), ...

More information about the Haskell-Cafe mailing list