Scala类型推断和多个参数列表
(Scala 2.11.8)
考虑下面的代码:
trait Class[A] {
  def f1[B >: A](arg1: Int)(ord: Ordering[B]): Int
  def f2[B >: A](arg1: Int, ord: Ordering[B]): Int
  def f[B >: A](ord: Ordering[B]): Int = {
    f1(123)(ord) // Compilation error!
    f2(123, ord) // OK
  }
}
  这里,行f1(123)(ord)引起type mismatch; found : Ordering[B] required: Ordering[A] Note: B >: A, but trait Ordering is invariant in type T. You may wish to investigate a wildcard type such as _ >: A. (SLS 3.2.10) type mismatch; found : Ordering[B] required: Ordering[A] Note: B >: A, but trait Ordering is invariant in type T. You may wish to investigate a wildcard type such as _ >: A. (SLS 3.2.10) 
  如果我们将调用更改为f1[B](123)(ord) ,则错误消失。 
为什么多个参数列表的存在混淆了类型检查器? 这是一个错误还是预期的结果?
这不是一个错误 - 分离到参数列表意味着仅根据第一个参数列表推断出类型参数:
f1(123)(ord) 
可以改写为:
val partiallyApplied = f1(123)
partiallyApplied(ord)
  现在 - 什么是partiallyApplied的类型?  既然类型参数没有明确设置,而且也没有用于推断参数/返回类型,类型parametter被推断为A (有没有具体的B呢!所以partiallyApplied的类型(Ordering[A]) => Int ),因此在Ordering[B]使用它后面会给出例外。 
相反,当打电话时:
f2(123, ord)
  由于ord类型为Ordering[B] ,因此可以将type参数推断为B ,因此编译成功。 
