ndriscoll
4 months ago
> The compiler should understand the DSLs I’m writing and automatically map them to types it understands. If it needs more information—like a database schema—to figure that out, that information can be provided.
What you're describing are string interpolation macros, and e.g. Slick in Scala does this[0]. You write SQL with normal variable substitution, and it compiles to a prepared statement with bind values (so no SQL injection), and can optionally validate against your schema at compile time. Super simple to read, write, and maintain.
I've not done any frontend Scala, but apparently Binding.scala[1] offers similar functionality to make composable HTML templates with databinding based on string interpolation macros (boy was that a jargon-dense sentence to say "nice in lots of ways"). The readme says it's statically checked including HTML tags/attributes.
So yeah statically typed languages do also have template systems, and when you have macros + type inference, as you've guessed, you don't need to drop to dynamic types.