Scala3: Crafting Types Through Metaprogramming?

Just in case, here is what I meant by hiding ViewOf inside a type class (type classes is an alternative to match types). Sadly, in Scala 3 this is wordy. (version 1) import scala.annotation.experimental import scala.quoted.{Expr, Quotes, Type, quotes} // Library part trait View extends Selectable { def applyDynamic(key: String)(args: Any*): Any = { println(s”$key … Read more

Method Override with Scala 3 Macros

With new method Symbol.newClass (Scala 3.1.3) this becomes quite easy: import scala.annotation.experimental import scala.quoted.* object NewClass { inline def newClass[A]: A = ${newClassImpl[A]} @experimental def newClassImpl[A: Type](using Quotes): Expr[A] = { import quotes.reflect.* val name: String = TypeRepr.of[A].typeSymbol.name + “Impl” val parents = List(TypeTree.of[A]) def decls(cls: Symbol): List[Symbol] = List(Symbol.newMethod(cls, “func”, MethodType(List(“s”))(_ => List(TypeRepr.of[String]), _ … Read more