runtime reflection for classes

Johannes Waldmann waldmann at
Thu Feb 9 05:43:38 EST 2006

With Data.Generics, we can get an object's type, constructor and fields.
I think there should be way to get the object's class(es) and methods.
E. g. I want to find out whether the object's type implements Show,
and if so, call the show  method (and if not, call some replacement).
see also

I know this is again specific to one-parameter type classes.
But still, these things occur frequently, don't they.
As for classes with more parameters, I guess implementation-wise
it is about how to get a representation of the dictionary,
and syntax-wise it is about how to specify what dictionary we want.

Also I know that Metaprogramming should be done at compile time
rather than at run time (as far as possible),
and I know that Template Haskell does offer a lot in that direction.
But with TH, you construct an abstract source code representation.
My idea here is different:
I want to write concrete source code that inspects (runtime)
type information. (So I don't have to worry about monads generating
unique names etc.)

Respectfully submitted,
-- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 --
---- -------

More information about the Haskell-prime mailing list