On Mon, Aug 3, 2015 at 11:02 AM, Zemyla <
zemyla@gmail.com> wrote:
>
> 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 be:
>
> 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.
>
> So:
> 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?