Re: How to convert the type signature of a variable to a String?
G'day all. Mon, 9 Apr 2001 11:52:47 +0200, Pasch, Thomas (ACTGRO) <[EMAIL PROTECTED]> pisze: > > For example: > > > > 'function f' gives the String "a->a" On Sat, Apr 14, 2001 at 08:28:16PM +, Marcin 'Qrczak' Kowalczyk wrote: [...] > 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). I think I understand what you're saying, but I'd just like to understand this practically. We know that the most general type of `id' is "a->a". We assume there's a theoretical function: get_the_function_type_of :: a -> String where a can be a function type. Now consider: f :: (String -> String) -> String f g = g (get_the_function_type_of g) The question is: Should `f id' return "a->a" or "String->String"? Cheers, Andrew Bromage ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: How to convert the type signature of a variable to a String?
Mon, 9 Apr 2001 11:52:47 +0200, Pasch, Thomas (ACTGRO) <[EMAIL PROTECTED]> 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 * [EMAIL PROTECTED] http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users