Jamie Thompson MIRRORS FOR OPERATIONS, NOT DATA Scalar Conference 2024

Поделиться
HTML-код
  • Опубликовано: 5 окт 2024
  • 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

Комментарии • 3

  • @Jankoekepannekoek
    @Jankoekepannekoek 4 месяца назад +1

    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.

    • @jamie_thompson_
      @jamie_thompson_ 4 месяца назад +1

      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.

    • @Jankoekepannekoek
      @Jankoekepannekoek 4 месяца назад

      @@jamie_thompson_ Good to know! Thanks!