Skip to content
0:00 / 0:00

#scala3#macros#metaprogramming

Compile-Time Time! — Data Transmogrification Macro From Scratch — Part 1

Kit Langton

5.3K subscribers • 2 videos on Hallway

YouTube

Advanced. Deep dive for people who know the field.

2.1K views3 years ago1 recommendation

Programming languagesScalaCompilers and interpreters

Kit Langton demonstrates how to build a Scala 3 macro from scratch to automate data-transformation boilerplate.

In this video, I'll walk you through the implementation of a nontrivial Scala 3 macro from scratch that can automate data-transformation boilerplate (essentially we'll construct a simplified, pedagogical replica of the wonderful Chimney/DuckType libraries) Part 2: youtu.be/w7pzqHXGnf8 Repo: github.com/kitlangton/compile-time-time

Why it's here

1 person recommends this

What people say. Recommended as a practical, step-by-step tutorial for learning Scala 3 metaprogramming and macro development.

u/HombrexGSPin r/scala • Recommends

On “Scala 3 macros course?”

…f you want to learn the math behind it. There is also a lot of tutorials in YouTube, not talking about the subject but rather explaining it at the same time they are using it to write a library or something practical. I bet you probably have seeing a lot of them before, though I can put two or three videos that I personally find somehow usefull. link to this video (Kit Langton) link to this video (Xebia Functional) link to this video (Ziverge) Hope you find some references and a good tutorial soon, and If so, I would love if you mention it in this post ❤️…

u/ragharin r/scala • Mentions

On “How to write Scala Macro to copy values from one case class to another where the field names are identical.”

If you want to use some existing solution, there are: - Chimney (Scala 2.12/2.13/3) - macros - Ducktape (Scala 3 only) - macros + Mirrors - Henkan (Scala 2.12/2.13) - Shapeless If you want to learn: It is absolutely possible to write such a thing without writing macros: - Chimney was originally created with Shapeless - Ducktape originally used only `Mirror`s and `inline def`s - Henkan still uses only Shapeless That said: it impractical in a long run: - both Shapeless and Mirrors impose runtime penaly - you have to create your instances through intermediate layers, which might have O(n) allocations (where n is the number of fields in your case class). You cannot _just_ call the c…