この質問は深いタイプのレベルプログラミングであり、私の失敗は知識の不足によるものであることは知っています。私は少なくともこれをコンパイルする方法を知りたいです。私はtuple2がコンテキスト内でHigher-Kinded型になることを理解するためにコンパイラが必要です。暗黙の解像度とタイプlambdaの比較
trait Extract[T[_],A]{
def extract(t: T[A]): A
}
object Extract{
type T2[B] = {type l[X] = (X,B)}
implicit def forTuple2[A,B] = new Extract[T2[B]#l,A] {
override def extract(t: (A, B)): A = t._1
}
}
def method[T[_],A](a: T[A])(implicit extractor: Extract[T,A]): A = extractor.extract(a)
method[Extract.T2[String]#l,Int]((1,"hi")) //this works but is useless.
//the whole point is to get the compiler to do the heavy lifting And in
//this case it means inferring that a tuple2 of (X,whatever) is a T[X] for the context
できるだけ私の目標に近いものをいただければ幸いです。私もシェイプレスは、このものに専用のライブラリを持って知っている。しかし、私の問題を解決するために形のないものが存在しないと仮定しよう。
"あなたはまだ何も見ていません(͡°͜ʖ°)"私は心配しています:) – shayan