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

Scala macros: What is the difference between typed (aka typechecked) and untyped Trees

Theoretical part This is an architectural peculiarity of scalac that started leaking into the public API once we exposed internal compiler data structures in compile-time / runtime reflection in 2.10. Very roughly speaking, scalac’s frontend consists of a parser and a typer, both of which work with trees and produce trees as their result. However … 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