How to convert the type signature of a variable to a String?

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
14 Apr 2001 20:28:16 GMT


Mon, 9 Apr 2001 11:52:47 +0200, Pasch, Thomas (ACTGRO) <extern.thomas.pasch@volkswagen.de> pisze:

> So the question is: Is is possible to write a function the gives
> back a String with the signature of the argument of that function?
> 
> For example:
> 
>  'function f' gives the String "a->a" 

No. Classes are not powerful enough to "recognize polymorphism".
In this form it's not even theoretically consistent: any function
can be treated as a function of a more specific type, so the result
would be ambiguous (for example f has type Int->Int too, so asking
for a type should give "Int->Int" too).

The fact that a function can be treated as of more specific types than
originally defined is not a problem when the function is used, because
interpretations according to possible types agree. But when you want
to make a string out of it, they can't agree if they are not trivial:
a value can't behave as both strings "a->a" and "Int->Int".

In Haskell there are almost no cases where an ambiguity is resolved
implicitly, i.e. when one of several correct interpretations is chosen.
There are not many ambiguities at all, and they result in compile
errors if they arise.

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK