[Haskell-cafe] Typeclassable typeclass?

adam vogt vogt.adam at gmail.com
Tue Aug 4 20:02:32 UTC 2015


I think the same result could be done with template haskell, but probably
some cases might not end up working the way they should. For example, what
happens if the instance declaration needed is at the end of the file, what
happens if we make c ~ Typeclassable [to use your name]? I have an
incomplete sketch at <https://github.com/aavogt/IsInstance>

I have a feeling that Typeclassable / IsInstance raises the same objections
that OverlappingInstances does, since my TH code depends on that extension.

Regards,
Adam

On Mon, Aug 3, 2015 at 11:02 AM, Zemyla <zemyla at 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?

> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150804/a3808f9f/attachment.html>


More information about the Haskell-Cafe mailing list