Annotating instances

Jaro Reinders jaro.reinders at gmail.com
Sat Dec 2 14:50:50 UTC 2023


Hi GHC devs,

I'm working on a GHC plugin which implements a custom instance resolution 
mechanism:

https://github.com/noughtmare/transitive-constraint-plugin

Currently, I need to place instances in a specific order in a specific file to 
recognize them and use them in my plugin. I think my life would be a lot easier 
if I could put annotations on instances. I imagine a syntax like this:

     data MyInstanceTypes = Refl | Trans deriving Eq

     class f <= g where
       inj :: f x -> g x

     instance {-# ANN instance Refl #-} f <= f where
       inj = id

     instance {-# ANN instance Trans #-}
         forall f g h. (f <= g, g <= h) => f <= h
       where
         inj = inj @g @h . inj @f @g

Using this information I should be able to find the right instances in a more 
reliable way.

One more thing I was thinking about is to make it possible to remove these 
instances from the normal resolution algorithm and only allow them to be used 
by my plugin.

Do you think this would be easy to implement and useful? Or are there other 
ways to achieve this?

Cheers,

Jaro


More information about the ghc-devs mailing list