5

Is there a a function that can take a given context/[Pred] and simplify it?

Some examples for what I mean by that:

  • If the context contains Eq [a] replace it with Eq a (because it implies the more complicated constraint)
  • If the context contains Eq Int, filter that out
  • Remove duplications

Use case: I've implemented TH functions to derive instances, and these instances in turn use things like fmap so they require context, and I want to produce instances that will not generate redundant constraint warnings.

I already made a simplifyContext :: [Pred] -> Q [Pred] helper to do this, but as this sounds to me like a common need, I expect this possibly already exists in some library but I've tried to find it and haven't. Or if it doesn't exist perhaps that's because there's a simpler technique that I'm missing..

yairchu
  • 23,680
  • 7
  • 69
  • 109
  • Similar to (but not a duplicate of) https://stackoverflow.com/questions/67091316/detecting-redundant-constraints-in-haskell – Ari Fordsham Apr 27 '21 at 13:51

0 Answers0