Scala:三重上下文界限,未找到证据参数

Scala: Triple Context Bounds, evidence parameters not found

我已将其编辑为@Zhi Yuan Wang 回复的问题的更简单形式:

object ContBound { 
  def f2[A: Seq, B: Seq]: Unit = {
      val a1: Seq[A] = evidence
      val b2: Seq[B] = evidence 
     }

  def f3[A: Seq, B: Seq, C: Seq]: Unit = {
    val a1: Seq[A] = evidence
    val b2: Seq[B] = evidence
    val a3: Seq[C] = evidence      
  }   
}

我收到以下错误:

not found value evidence
not found value evidence
type mismatch; found :Seq[A] required: Seq[C]

尽管在 REPL 中得到以下内容:

 def f3[A: Seq, B: Seq, C: Seq]: Unit =
 |    {
 |       val a1: Seq[A] = evidence
 |       val b2: Seq[B] = evidence
 |       val a3: Seq[C] = evidence      
 |    }  
f3: [A, B, C](implicit evidence: Seq[A], implicit evidence: Seq[B], implicit evidence: Seq[C])Unit

小智的回答是正确的。以下编译:

object ContBound { 
  def f2[A: Seq, B: Seq]: Unit = {
    val a1: Seq[A] = evidence
    val b2: Seq[B] = evidence 
  }

  def f3[A: Seq, B: Seq, C: Seq]: Unit = {
    val a1: Seq[A] = evidence
    val b2: Seq[B] = evidence
    val a3: Seq[C] = evidence      
  }   
}

但是我仍然不认为这是正确的行为,因为这些是两种不同方法的参数,并且通常允许方法重用参数名称。

你试过了吗

def comma3[A: RParse, B: RParse, C: RParse, D](f: (A, B, C) => D): D =
    expr match {
       case CommaExpr(Seq(e1, e2, e3)) =>
           f(evidence.get(e1), evidence.get(e2), evidence.get(e3))
}

因为证据 $1 已经被

使用
def comma3[]??