lundi 13 février 2017

Higher-kinder types inference

Vote count: 0

(Scala 2.11.8)

Consider the following snippet:

class Case2 {
  trait Container[+A] {
    def addAll[B >: A, T2 <: Container[B]](that: T2): Boolean
  }

  def t1: Container[String] = ???
  def t2: Container[Int] = ???

  // Works
  t1.addAll[Any, Container[Any]](t2)

  // Errors:
  //* type mismatch; found : Case2.this.Descendant[Int] required: T2
  //* inferred type arguments [String,Case2.this.Descendant[Int]] do not conform to method addAll's type parameter bounds [B >: String,T2 <: Case2.this.Ancestor[B]]
  t1.addAll(t2)
}

Why can't last addAll call inference the proper least common denominator?

asked 40 secs ago

Let's block ads! (Why?)



Higher-kinder types inference

Aucun commentaire:

Enregistrer un commentaire