In Scala 2.7, I want to use a method as a parameter of another method of the same class.
I have a class and objects which are companions:
class mM(var elem:Matrix){
//apply a function on a dimension rows (1) or cols (2)
def app(func:Iterable[Double]=>Double)(dim : Int) : Matrix = {
...
}
//utility function
def logsumexp(): Double = {...}
}
object mM{
def apply(elem:Matrix):mM={new mM(elem)}
def logsumexp(elem:Iterable[Double]): Double ={
this.apply(elem.asInstanceOf[Matrix]).logsumexp()
}
}
Normally I use logsumexp like this mM(matrix).logsumexp
but if want to apply it to the rows I can't use mM(matrix).app(mM.logsumexp)(1)
, I get the error:
error: reference to mM is ambiguous;
it is imported twice in the same scope by
import mM
and import mM
What is the most elegant solution ? Should I change logsumexp() to another class ?
Thanks,=)