远程语法糖不适用于Scala中的BigInt

远程语法糖不适用于Scala中的BigInt,scala,import,syntactic-sugar,Scala,Import,Syntactic Sugar,我有一个SyntactCSugar类,我用它在一些文件中导入椭圆曲线上的语法糖 class SyntacticSugar[Point](curve : Curve[Point]) { case class EllipticOperand (p : Point) { def + (q : => Point) = curve.sum(p,q) def * (n : => BigInt) = curve.times(p,n) } implicit def PointToOperan

我有一个SyntactCSugar类,我用它在一些文件中导入椭圆曲线上的语法糖

class SyntacticSugar[Point](curve : Curve[Point])
{
case class EllipticOperand (p : Point)
{
  def + (q : => Point) = curve.sum(p,q)
  def * (n : => BigInt) = curve.times(p,n)
}
implicit def PointToOperand(p : Point) = EllipticOperand(p)

case class EllipticMultiplier (n : BigInt)
{
  def * (p : => Point) = curve.times(p,n)
}
implicit def BigIntToOperand (n : BigInt) = EllipticMultiplier(n)

case class EllipticInt (n : Int)
{
  def * (p : => Point) = curve.times(p,BigInt(n))
}
implicit def IntToOperand (n : Int) = EllipticInt(n)
}
我的用法如下:

trait Curve[T] {
  def sum(p: T, q: T): T
  def times(p: T, n: Int): T
}

// dummy implementation from Jasper-M (thanks)
class PointCurve extends Curve[Point] {
  override def sum(p: Point, q: Point) = Point(p.x+q.x, p.y+q.y)
  override def times(p: Point, n: Int) = Point(p.x*n, p.y*n)
}

问题是,如果我想做2*p,其中p:Point不起作用,而p*2和p+p就可以了

编译器说重载的方法值*带有替代项。。。无法应用于点a*p

如果糖只是粘贴在同一个文件中,而不是导入,那么它就可以完美地工作


这是怎么回事?

您的代码片段不是自包含的,没有点和曲线的定义,也没有向我们显示您得到的实际编译器错误。这让我很难帮助你。问题是点没有定义,但我理解,对不起,我会编辑。
val sugar = new SyntacticSugar(curve)
import sugar._