這是一個簡單的例子類型推斷和隱式鏈接
我有以下代碼:
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