Thanks for the example, but this has the same problem as the other examples WRT being relevant to what I’m trying to do: it’s checking against a known list of types.
I’ll try and explain a little more clearly I’m looking to do, as the provided examples seem to indicate I have not explained it well.
Raw Code
show"Tried to foo the $bar, and got a $baz instead"
Scala 2 expansion
new StringContext("Tried to foo the ", ", and got a ", " instead")
.show(
Shown.mat(bar)(implicitly[Show[Bar]]),
Shown.mat(baz)(implicitly[Show[Baz]])
)
This works because it’s driven by implicit conversions, which for Scala 2 only need to be enabled at the definition site. This approach would be extremely problematic because, at least according to my experiments, in Dotty (and thus presumably Scala 3) you need to import the feature flag at both the definition site and the use site. It makes zero sense to require enabling a feature known to make code less comprehensible on a near global level to opt-in to a feature intended to make code less error prone.
Ideal Scala 3 expansion
new StringContext("Tried to foo the ", ", and got a ", " instead")
.s(
bar.show(given summon[Show[Bar]]),
baz.show(given summon[Show[Baz]])
)
Unfortunately, this means that I need to be able to summon a known typeclass for each passed argument. While the compiler apparently knows these types, I can’t seem to find any documentation or example hinting at how to access so I can splice together the calls. I’ve found plenty of examples of how to check if it’s one of a handful of types, so I accept that the compiler has this information, but as far as I can tell, it’s completely inaccessible if you don’t know it ahead of time.
While the above is interesting because I’d like Curried Varargs so I can do this reasonably, it’s also a much simpler problem and if we can’t do this it casts signifiant doubt on the plausibility of implementing Curried Varargs via a macro (as was suggested).