scala self-type:成员类型参数错误
这是此问题的后续问题。
为什么此代码无法编译,如何修复?
trait Vec[V] { self:V =>
def -(v:V):V
def dot(v:V):Double
def norm:Double = math.sqrt(this dot this)
def dist(v:V):Double = (this - v).norm
}
错误是:
Vec.scala:6: error: value norm is not a member of type parameter V
def dist(v:V):V = (this - v).norm
^
This is a followup to this question.
Why does this code not compile, and how do I fix it?
trait Vec[V] { self:V =>
def -(v:V):V
def dot(v:V):Double
def norm:Double = math.sqrt(this dot this)
def dist(v:V):Double = (this - v).norm
}
The error is:
Vec.scala:6: error: value norm is not a member of type parameter V
def dist(v:V):V = (this - v).norm
^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将 - 的定义更改为
By changing the definition of - to
正确的解决方案是:
向 Debilski 提供道具,以获取 相关问题。
The proper solution is:
Props to Debilski for the answer to a related question.