为什么scala隐含def而不是更高阶的类型能够获取我的部分类型?

时间:2017-02-28 22:43:56

标签: scala

我遇到了一个问题,其中scala隐式isnt'能够匹配类型声明,这是一种更高阶类型的部分应用

implicit def extensions[F[_], A](m: F[A]) = new {
 def foundIt() = ()
}

case class Foo[T](x: T)
val f1: Foo[Int] = Foo(42)
f1.foundIt() // Implicit is able to match and infer
type FooType[T] = Foo[T]
val f2: FooType[Int] = Foo(42)
f2.foundIt() // Implicit is able to match and infer

case class Foo2[T, V](x: T, y: V)
val f3: Foo2[Int, Double] = Foo2(4, 2.0)
// f3.foundIt()  // Doesn't work of course
type Foo2Type[T] = Foo2[T,Double]
val f4 : Foo2Type[Int] = Foo2(42,2.0)
// f4.foundIt() // Why doesn't this work ...
extensions[Foo2Type,Int](f4).foundIt() //  if this works?

这是scala的限制吗?类型声明的类型是否与scala无法匹配和推断?

0 个答案:

没有答案