[Haskell-cafe] Typeclassable typeclass?
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.
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
> class (Typeable a) => Typeclassable a where
> typeClass :: (Typeable c) => proxy c -> proxy' a -> ((c a) => 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?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe