【发布时间】:2017-10-26 13:05:09
【问题描述】:
以下代码
type Id[+A] = A
type ReprF[A, F[_]] = Unit
type Repr[A] = ReprF[A, Id]
在 Scala 2.12 中无法编译,出现错误
covariant type Id occurs in invariant position in type
[A]Playground.this.ReprF[A,Playground.this.Id] of type Repr
我不明白为什么Id 的协方差会阻止这段代码编译。
ReprF 不应该关心F 是否是协变的,它只需要一种类型的* -> *。
我错过了什么吗?
奇怪的是它在 Scala 2.11 中可以正确编译。
这是scastie snippet,如果您想尝试一下代码。任何帮助将不胜感激!
【问题讨论】:
标签: scala covariance higher-kinded-types type-alias