限制隐式参数和视图/上下文边界组合的原因是什么?

发布于 2024-11-26 04:56:58 字数 177 浏览 9 评论 0原文

最近对 Scala master 的提交之一消除了对上下文/视图边界与隐式参数。这是一个很大的改进,减少了样板文件的数量,但是之前做出这种限制的原因是什么,现在我们可以预期什么后果?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水波映月 2024-12-03 04:56:58

上下文和视图边界添加隐式参数。因此,如果您这样写:

def f[T : Manifest](l: List[T])(implicit ord: Ordering[T]) 

事实上,传递的是两个 隐式参数,而不是一个。允许这种语法肯定会导致一些混乱。由于类型类的存在,隐式参数的使用开始变得更加广泛,能够执行上述操作会很有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文