One of the recent commits to Scala master removes restriction on combining context/view bounds with implicit parameters. That's a great improvement that reduces amount of boilerplate, but what was the reason of making that restriction before, and what consequences can we expect now?
What was the reason to restrict on combining implicit parameters and view/context bounds?
Asked Answered
Context and view bounds add implicit parameters. So if you write:
def f[T : Manifest](l: List[T])(implicit ord: Ordering[T])
There are, in fact, two implicit parameters being passed instead of one. Allowing this kind of syntax will certainly result in some confusion down the road. As implicit parameter usage starts to get more widespread, because of type classes, being able to do something like the above is helpful.
"Context and view bounds add implicit parameters" >> sure, I know that. I was rather interested, if it's caused with any technical difficulty. –
Asteroid
IMO, not being able to use the bounds along with implicit parameters might also be very confusing for a newbie :) –
Asteroid
@Vasil I'm not saying it is a bad decision, just that it adds a certain degree of... confusion. It would be illegal to call the above function like
f(List(1 -> 2, 2 -> 1))(Ordering by (_.swap))
, even though it seems to have all parameter lists filled correctly. –
Agler © 2022 - 2024 — McMap. All rights reserved.