scalacontext-bound

Scala: Triple Context Bounds, evidence parameters not found


I have edited this to a simpler form of the question to which @Zhi Yuan Wang responded :

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

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

I get the following errors:

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

despite getting the following in the REPL:

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

Zhi's awnser is correct. The following compiles:

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

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

However I still don't see this as correct behaviour, as these are parameters for two different methods and methods are normally allowed to reuse parameter names.


Solution

  • Have you tried

    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$3.get(e1), evidence$4.get(e2), evidence$5.get(e3))
    }
    

    since the the evidence$1 already used by

    def comma3[]??