[Haskell-cafe] Typeclassable typeclass?

Zemyla zemyla at gmail.com
Mon Aug 3 15:02:25 UTC 2015

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.

What if there were a typeclass called Typeclassable, whose definition would

class (Typeable a) => Typeclassable a where
    typeClass :: (Typeable c) => proxy c -> proxy' a -> ((c a) => b) -> b
-> b

So, for a simple example, you might have:
nubT :: (Typeclassable a, Eq a) => [a] -> [a]
nubT ls = typeClass (Proxy :: Proxy Ord) ls (nubOrd ls) (nub ls)

where nubOrd is a suitable implementation of nub that requires Ord a.

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.

1) Can this be implemented with GHC as it is now?
2) Could this be implemented at all with any reasonable amount of work?
3) Should this be implemented? Would the benefits outweigh the costs?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150803/2e056160/attachment.html>

More information about the Haskell-Cafe mailing list