Use context bound in type alias

后端 未结 2 1290
梦谈多话
梦谈多话 2021-01-04 14:15

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

e.g

type U = A : B
2条回答
  •  佛祖请我去吃肉
    2021-01-04 15:16

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

    For instance:

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

    is a shorthand form for

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

    and this cannot be represented in a type definition.

提交回复
热议问题