<p dir="ltr">I apologize if this has been discussed and dismissed before, but I figured with Typeable being made entirely automatic by GHC, this might have a shot at working.</p>
<p dir="ltr">What if there were a typeclass called Typeclassable, whose definition would be:</p>
<p dir="ltr">class (Typeable a) => Typeclassable a where<br>
    typeClass :: (Typeable c) => proxy c -> proxy' a -> ((c a) => b) -> b -> b</p>
<p dir="ltr">So, for a simple example, you might have:<br>
nubT :: (Typeclassable a, Eq a) => [a] -> [a]<br>
nubT ls = typeClass (Proxy :: Proxy Ord) ls (nubOrd ls) (nub ls)</p>
<p dir="ltr">where nubOrd is a suitable implementation of nub that requires Ord a.</p>
<p dir="ltr">Basically, my first thought for the implementation of Typeclassable is that it contains all the dictionaries for a in a hashtable, and searches through them with the typeRep of c.</p>
<p dir="ltr">So:<br>
1) Can this be implemented with GHC as it is now?<br>
2) Could this be implemented at all with any reasonable amount of work?<br>
3) Should this be implemented? Would the benefits outweigh the costs?</p>