Hacker News new | ask | show | jobs
by maybevoid 461 days ago
Shameless plug: I am working on a solution in Rust that solves the coherence problems discussed in this post. I call it Context-Generic Programming (CGP), which makes it possible to write modular code that is generic over a context (Self) type without the coherence restrictions.

The basic idea of CGP is pretty simple: we introduce a companion provider trait that has an additional generic parameter that is placed at the "Self" position of the trait, and define a unique provider type that identifies each of the generic implementation. CGP then makes use of blanket implementations and macros to enable wiring of generic providers to a concrete context to implement the original trait, which we now call a consumer trait.

You can read about the full details of CGP at https://contextgeneric.dev/. I am also writing a book for CGP at https://patterns.contextgeneric.dev/, which goes more into details on how it works behind the scene.

Currently, I am preparing for a new v0.4.0 release of CGP, which includes a lot of quality of life improvements, including significantly improved error messages. I will also write a follow up blog post to specifically address how CGP can be used to solve the coherence problems stated in this post. So do stay tuned for more updates on CGP!