1
我有以下特點:無法解析符號A
sealed trait Sum[+A, +B]
final case class Failure[A](value: A) extends Sum[A, Nothing]
final case class Success[B](value: B) extends Sum[Nothing, B]
object Sum {
def flatMap[AA >: A, B, C](s: Sum[AA, B], f: B => Sum[AA, C]): Sum[AA, C] =
s match {
case Failure(v) => Failure(v)
case Success(v) => f(v)
}
def fold[A, B, C](s: Sum[A, B], success: A => C, failure: B => C): C =
s match {
case Failure(v) => failure(v)
case Success(v) => success(v)
}
def map[A, B, C](s: Sum[A, B], success: A => C): Sum[A,C] =
fold(s, succ => Success(success(succ)), fail => Failure(fail))
}
和編譯器抱怨:
Cannot resolve symbol A
由:
flatMap[AA >: A, B, C]
我在做什麼錯?
沒有給出一個行數? – Harald