Scala 2.7:引用不明确(导入两次)
在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() 更改为另一个类吗?
谢谢,=)
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,=)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终只在我的 mM 类中使用了 new mM(matrix) 而不是 mM(matrix) 语句,并避免了错误。
@Rex Kerr:你是对的,我将类型更改为
Matrix
。谢谢
I finally only used
new mM(matrix)
and notmM(matrix)
statements inside my mM Class and avoided the error.@Rex Kerr : You are right I changed the type to
Matrix
.Thanks