Could Type Macros be a thing?

In scala 3 we have inline methods, which allow some of the power of macros, and then macros themselves. While using macros, I have found myself wishing for a similar thing to exist for match types: type macros. In a library I’ve been writing, I’m synthesizing refinement types for programmatic structural types like so:

case class div_t(quot: Int, rem: Int)
//pst derived from div_t
Ptr[div_t] { val quot: Ptr[Int]; val rem: Ptr[Int]}

Generating this type is easy, but users have to write types like Ptr[div_t] for my library, and writing the full refinement can be both annoying and complex depending on the product type the Ptr has. Currently I use an extension method named partial to add this refinement on user request, but I’d much rather have something like:

class PtrBacking[A] extends Selectable
transparent inline type Ptr[A] = ‘[ptrImpl[A]]
def ptrImpl[A: Type](using Quotes): Type[?]
 Ptr[div_t] =:= PtrBacking[div_t] { val quot: Ptr[Int]; val rem: Ptr[Int]}
1 Like