Is there a way to emit a warning when GHC resolves a specific instance?

Imagine you have a typeclass for monads in which you can call evaluate:

class Monad m => MonadEvaluate m where
  evaluate :: a -> m a

Essentially only IO (and stacks based on IO) have a proper instance, however Identity instance with evaluate = pure may be useful for pure tests. However, this instance shouldn’t be used in production, as it’s not evaluating anything.

Is there a way to emit a GHC warning each time GHC uses/produces a dictionary MonadEvaluate Identity? I’d like to have something like

instance 
  {-# WARNING "Instance MonadEvaluate Identity should only be used in tests" #-} 
  MonadEvaluate Identity where
  evaluate = pure

however it’s not working. Can I achieve such a behaviour in some other way?

There’s a dormant proposal about type warnings (similar to TypeError):

1 Like

There’s also a much less dormant proposal about pretty much exactly this feature (adding WARNING pragmas to instances):

2 Likes

Cool, didn’t know there already is such a proposal. Thanks for links.