Jamie Thompson MIRRORS FOR OPERATIONS, NOT DATA Scalar Conference 2024
ฝัง
- เผยแพร่เมื่อ 5 ก.พ. 2025
- Can we derive endpoints from just a trait definition?
One of Scala's strengths is domain modelling, and from a data definition, we can derive generic information in a Mirror, e.g. to generate type classes. For operations (such as endpoints) there is less support from metaprogramming, so we often create DSLs to describe them. I propose that we can extend Mirrors to operations, and use the most natural DSL of all - plain trait definitions.
scalar-conf.com/
Scalar Conference 2024
powered by SoftwareMill
#scalarconf
I am quite surprised this could be done without a change in the compiler! I suppose the 'derived' method on the typeclass' companion object has no restriction on the type of the first argument then.
you're right, "derives Foo" really has only one restriction, that Foo has 1 type parameter. The desugaring is very flexible, it's up to the "derived" method to impose any restrictions. For example, if you ask for a scala.deriving.Mirror evidence, then the compiler enforces some rules before it will synthesize a mirror for you.
@@jamie_thompson_ Good to know! Thanks!