2

Scala 2.7 では、メソッドを同じクラスの別のメソッドのパラメーターとして使用したいと考えています。

コンパニオンであるクラスとオブジェクトがあります。

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()
    }
}

通常、私はこのようにlogsumexpを使用mM(matrix).logsumexpしますが、使用できない行に適用したい場合はmM(matrix).app(mM.logsumexp)(1)、エラーが発生します:

error: reference to mM is ambiguous;
it is imported twice in the same scope by
import mM
and import mM

最もエレガントなソリューションは何ですか? logsumexp() を別のクラスに変更する必要がありますか?

ありがとう、=)

4

1 に答える 1

0

最終的に、mM クラス内のステートメントのみを使用new mM(matrix)し、エラーを回避しました。mM(matrix)

@Rex Kerr:そうです、タイプをに変更しましたMatrix

ありがとう

于 2010-05-04T09:36:20.733 に答える