How to make an instance polymorphic over constraints?

Hi

I’m working on a compiler in tagless final style.

How can I make sort of memoizer more polymorphic of constraints?

Using ~ doesn’t work