Tweak to the syntax of extension methods

Mark "Justin" Waks
1 min readOct 27, 2019

--

A small item in Dotty News today: this PR from Martin changes the placement of type parameters when defining extension methods.

Basically, the change is that the type parameter comes first in the declaration. It looks a little odd:

def [T](xs: List[T]) append (ys: List[T]): List[T] = ...

But IMO the arguments given at the link are good ones, and I think the intuition — that you should always declare the type parameter before you use it — makes sense and is teachable. So it’s likely a net positive.

Usual caveats: this is just a PR, not merged to master, much less a Scala 3 SIP. But it makes sense, so I suspect this one has legs; YMMV…

--

--

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