1
我有這樣的代碼:Writer可以做協變嗎? WriterT [F [_],W,A]可以用+ A來聲明嗎? (解決)
type StringValidation[+A] = Validation[String, A]
type WriterValidation[A] = WriterT[StringValidation, String, A]
type Result[A] = WriterValidation[A]
private def someResult: Result[Int]
def implementTrait: Result[Any] = someResult // type mismatch
它給類型不匹配,發現Result[Int]
,需要Result[Any]
,但如果將它改變爲:
type WriterValidation[+A] = WriterT[StringValidation, String, A]
它給出「協變型中出現在WriterT中不變的位置...「
它發生在我身上,操作應該在概念上是好的,Validation
可以是協方差,爲什麼WriterT
不能(或不是)下降WriterT[F[_], W, +A]
(或甚至+W
)?
我正在使用scalaz7快照,但是我看到6.0.4中的WriterT的聲明是相同的。
事實證明,我使用了錯誤的版本,我使用的是"org.scalaz" %% "scalaz-core" % "7.0-SNAPSHOT"
,有一次我切換到"org.scalaz" % "scalaz-core_2.9.2" % "7.0.0-M2"
它的確定
事實證明,我使用了錯誤的版本,我所用的是' 「org.scalaz」 %% 「scalaz核」 %「7.0-SNAPSHOT 「',一旦我切換到'」org.scalaz「%」scalaz-core_2.9.2「%」7.0.0-M2「'沒關係 – Chris