加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 了解类型投影

发布时间:2020-12-16 10:00:37 所属栏目:安全 来源:网络整理
导读:从 non/kind-projector开始,有什么区别: // partially-applied type named "IntOrA"type IntOrA[A] = Either[Int,A] 和 // type projection implementing the same type anonymously (without a name).({type L[A] = Either[Int,A]})#L ? 它们是等价的吗?
从 non/kind-projector开始,有什么区别:

// partially-applied type named "IntOrA"
type IntOrA[A] = Either[Int,A]

// type projection implementing the same type anonymously (without a name).
({type L[A] = Either[Int,A]})#L

它们是等价的吗?

解决方法

它们几乎相同,正如评论中所说的那样.

假设你有一个类特性超级[F [_]] {},并且你想要实现它,其中F [x] = [Int,x]
你可以写:

type IntOrA[A] = Either[Int,A]
class B extends Super[IntOrA] {}

但如果你想要一个班轮,你可以写:

class B extends Super[({type L[A] = Either[Int,A]})#L] {}

或者使用亲切的投影仪,你可以写它:

class B extends Super[λ(A => Either[Int,A])] {}

甚至:

class B extends Super[Either[Int,?]] {}

除了使它成为一行并且具有这种类型的匿名之外没有其他区别.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读