Scala : reference is ambiguous (imported twice)

Posted by tk on Stack Overflow See other posts from Stack Overflow or by tk
Published on 2010-04-30T09:40:41Z Indexed on 2010/04/30 9:47 UTC
Read the original article Hit count: 182

Filed under:
|
|

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,=)

© Stack Overflow or respective owner

Related posts about scala

Related posts about ambiguous