[Haskell] detecting existing instances

Jorge Marques Pelizzoni jpeliz at icmc.usp.br
Wed Jan 9 11:23:46 EST 2008

Hi, all! I guess this belongs to haskell-cafe or glasgow-haskell-users,
but I've already been there and got no replies. Thanks in advance for
anyone taking the time to read on.

Given two type classes A t and B t, I'd like the typechecker to derive
different A t instances depending exactly on whether t is an instance of
B. In other words, is it possible to define a class (actually a type-level
function) IsB t f such that:

IsB t HTrue <=> instance (B t) exists
IsB t HFalse <=> otherwise?

If not, is this wish intrisically pointless?

After experimenting a bit with multiparameter classes, overlapping
instances and suchlike, it looks like Haskell is being purposedly designed
not to support this. Yes, I believe that would require the typechecker to
take a whole new theorem-proving (undecidable?) stance :o) On the other
hand, any interesting type-level programming seems to require
undecidable+overlapping instances, so we are usually working on
undecidable grounds...

Sorry if this is an overdebated matter (is it?), but searching through the
endless haskell archives is not trivial. Thanks in advance for any
pointers or thoughts on the matter.



More information about the Haskell mailing list