Mixing params, mixing macros

Mark "Justin" Waks
2 min readSep 27, 2019

--

This bit of Dotty news isn’t as dramatic as many of the ones I mention here — it’s not a big new feature or anything — but it’s still something that many of us have been hoping for for a long time. There’s now an open PR to allow you to mix conventional and “given” (what we used to call “implicit”) parameter lists freely in a function declaration.

This is a big deal because of dependent types, one of Scala’s subtler but more important features. In theory (and mind, I haven’t played with this yet, so I could be wrong), it means that you can write a function like this:

def foo(a: A)(given b: B)(c: b.C): D = ...

That is, the type of parameter c depends on the type of given parameter b. This means you can directly build relatively complex chains of types in your function calls, where some of the links are implicit; this requires a fair amount of working-around in Scala 2.

In the same general category of “reducing Scala 2 pain points in power features”, there’s also a draft PR, which tries to make it possible to define macros in the same project in which you use them.

This is one of those details that has long been a mild annoyance: the fact that macros have to be in a separate project generally introduces extra sbt ceremony to applications that use them; it’s one of the many reasons why macros are kind of scary in Scala 2.

Given that macros are intended to be much more solid in Scala 3 — they’re getting properly spec’ed, they are much more carefully designed, and are no longer tied to compiler internals — I expect folks to use them a good deal more. (Certainly I look forward to using them myself, whereas I’ve traditionally avoided them due to the “experimental” label.) So making it easier to use them is a clear win.

Usual caveats: there are just PRs — not merged to Dotty master, much less started on the road to official Scala 3. (The macro one isn’t even a full PR yet: it explicitly requires more work before it’s fully functional.) So nothing is certain here. But they’re both helpful enhancements, so I hope they make it in…

--

--

Mark "Justin" Waks
Mark "Justin" Waks

Written by Mark "Justin" Waks

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

No responses yet