这是一个简单的例子类型推断和隐式链接
我有以下代码:
import scala.language.implicitConversions
trait Mapping[I, O]
trait KeyMapping[K, I, O]
implicit def toMapping[I, O](s: I => O): Mapping[I, O] = ???
implicit def toKeyMapping[K, I, O](s: (K, I => O))(
implicit ev: (I => O) => Mapping[I, O]): KeyMapping[K, I, O] = ???
def test[K, I, O, M](s: M)(
implicit ev: M => KeyMapping[K, I, O]
):KeyMapping[K, I, O] = ???
val x = test(1 -> {s:String => true})
^
这提供了以下错误:
type mismatch;
found: ((Int, Nothing => Boolean)) => KeyMapping[Int,Nothing,Boolean]
required: ((Int, String => Boolean)) => KeyMapping[Int,Input,Boolean]
这是为什么?
可以解决这个问题吗?
我其实需要'M',我忘了说这是个简单的例子 – EECOLOR