在类型别名中使用上下文绑定 [英] Use context bound in type alias

查看:40
本文介绍了在类型别名中使用上下文绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Scala 的类型别名中使用上下文边界?

Is it possible to use context bounds in type aliases in Scala?

例如

type U = A : B

推荐答案

不,因为上下文绑定实际上是额外隐式参数的简写.

No, because the context bound is actually a shorthand for an extra implicit parameter.

例如:

def sort[A : Ordering](xs: Seq[A])

def sort[A](xs: Seq[A])(implicit ordering: Ordering[A])

这不能在类型定义中表示.

and this cannot be represented in a type definition.

这篇关于在类型别名中使用上下文绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆