scala complains about "missing parameter type" for placeholder in method update of implicit class: only when decorating scalaSci.EJML.Mat (but not when decorating IndexedSeq[Int] or Vector[Int])

101 views
Skip to first unread message

dREPLACEeLETTEReEjBYeLETTEReAatGMA ILcom

unread,
Nov 13, 2013, 9:07:08 AM11/13/13
to scalalab-...@googlegroups.com
In the code below, I have build two implicit classes, the first decorating Mat, the second decorating IndexedSeq[Int]. The methods update of these implicit classes do not behave similarly (for the method combine all is OK). Why ?

Can someone fix utilities_Mat or at least explain how my combination of placeholder _, and implicit classes can distinguish between Mat and IndexedSeq[Int]

I have first seen that problem in a long code, and have simplified a lot that code before showing it to scalalab-dev-group.

Here is the code:

import scalaSci.EJML.Mat
import scala.collection.immutable.IndexedSeq
import scala.language.implicitConversions
import scala.language.reflectiveCalls

implicit def VecDecorator(d: Vector[Int]) = new {
def update  (f: (Int,Int) => Int, s:Vector[Int]) =
(0 until   d.size) map (nrow => f(1,2))
def combine (f: (Int,Int) => Int, s:Vector[Int]) =
(0 until   d.size) map (nrow => f(1,2))
}

implicit def SeqDecorator(d: IndexedSeq[Int]) = new {
def update  (f: (Int, Int) => Int, s: IndexedSeq[Int]) =
(0 until   d.length) map (ncol => f(d(ncol),s(ncol)))
def combine (f: (Int, Int) => Int, s: IndexedSeq[Int]) =
(0 until   d.length) map (ncol => f(d(ncol),s(ncol)))
}

implicit def MatDecorator(d: Mat) = new {
def update  (f: (Double,Double) => Double, s:Mat) =
(0 until   d.Nrows) map (nrow => f(d(nrow,0),s(nrow,0)))
def combine (f: (Double,Double) => Double, s:Mat) =
(0 until   d.Nrows) map (nrow => f(d(nrow,0),s(nrow,0)))
}

    val work=new Vector[Int](0,2,1)
      work.combine(_ * _,work)// ok.
      work(_ * _)=work// ok
      work.update(_ * _,work)// ok

    val good:IndexedSeq[Int]=(0 to 2)
      good.combine(_ * _,good)// ok
      good(_ * _)=good// ok
      good.update(_ * _,good)// ok

    val bad=new Mat(2,2)
      bad.combine(_ * _,bad)// ok.
      bad(_ * _)=bad// missing parameter type for expanded function ((x$7, x$8) => x$7.$times(x$8))
      bad.update(_ * _,bad)// same error.
      bad.update((a:Double, b:Double) =>a*b,bad)// ok

Here is the output of Scalalab :

import scalaSci.EJML.Mat
import scala.collection.immutable.IndexedSeq
import scala.language.implicitConversions
import scala.language.reflectiveCalls
VecDecorator: (d: Vector[Int])AnyRef{def update(f: (Int, Int) => Int,s: Vector[Int]): scala.collection.immutable.IndexedSeq[Int]; def combine(f: (Int, Int) => Int,s: Vector[Int]): scala.collection.immutable.IndexedSeq[Int]}
SeqDecorator: (d: scala.collection.immutable.IndexedSeq[Int])AnyRef{def update(f: (Int, Int) => Int,s: scala.collection.immutable.IndexedSeq[Int]): scala.collection.immutable.IndexedSeq[Int]; def combine(f: (Int, Int) => Int,s: scala.collection.immutable.IndexedSeq[Int]): scala.collection.immutable.IndexedSeq[Int]}
MatDecorator: (d: scalaSci.EJML.Mat)AnyRef{def update(f: (Double, Double) => Double,s: scalaSci.EJML.Mat):...
<console>:144: error: missing parameter type for expanded function ((x$15, x$16) => x$15.$times(x$16))
                    bad(_ * _)=bad// missing parameter type for expanded function ((x$7, x$8) => x$7.$times(x$8))
                        
<console>:145: error: missing parameter type for expanded function ((x$17, x$18) => x$17.$times(x$18))
                    bad.update(_ * _,bad)// same error.

The shell command calling Scalalab is the same as the beggining of https://groups.google.com/group/scalalab-dev-group/attach/986785ba0c92dbb7/startup_and_console.txt?part=4&authuser=0

dREPLACEeLETTEReEjBYeLETTEReAatGMA ILcom

unread,
Nov 13, 2013, 9:21:24 AM11/13/13
to scalalab-...@googlegroups.com


Le mercredi 13 novembre 2013 15:07:08 UTC+1, dREPLACEeLETTEReEjBYeLETTEReAatGMA ILcom a écrit :
In the code below, I have build two implicit classes, the first decorating Mat, the second decorating IndexedSeq[Int].
Three classes to be exact, the third decorating Vector[Int] and working nicely as well.
 
Reply all
Reply to author
Forward
0 new messages