class Summation[T : Summable](baseValue : Signal[T]) extends {
private val _baseSignal = new Mutable[T, T](Val(implicitly[Summable[T]].zero), implicitly[Summable[T]].sum(_, _))
} with WrappedSignal[T](_baseSignal) {
def +=(value : Signal[T]) = _baseSignal.applyMutator(value)
}
I get an error on line two that it "could not find the implicit value for argument e/not enough arguments for method implicitly".
class Summation[T](baseValue : Signal[T]) (implicit summable : Summable[T]) extends {
private val _baseSignal = new Mutable[T, T](Val(summable.zero), summable.sum(_, _))
} with WrappedSignal[T](_baseSignal) {
def +=(value : Signal[T]) = _baseSignal.applyMutator(value)
}
I get the compile error "implicit modifier cannot be used for top-level objects" on the first line. If I remove the reference to summable in the early initializer, then the compile error goes away, although this makes it impossible to pass the signal into the base class constructor.
Is this a compile bug, or is it an intentional restriction that implicit parameters cannot be used inside early initializers? I can't think of a logical reason this would be invalid, except for perhaps some practical limitation of the implementation of implicits by the compiler.
Also, I'm using Scala 2.10.2 with the latest stable Scala IDE.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
class Promotable[T] private(baseValue : Signal[T], ordering : Ordering[T]) extends {
private val _baseSignal = new Mutable[T, T](baseValue, ordering.max(_, _))
} with WrappedSignal(_baseSignal) {
//Workaround for SI-3439 - https://issues.scala-lang.org/browse/SI-3439
def this(baseValue : Signal[T]) (implicit ordering : Ordering[T]) = this(baseValue, ordering)
def promoteTo(value : Signal[T]) = _baseSignal.applyMutator(value)
}
Hmm...strangely, my workaround doesn't seem to work. It seemed to compile initiallly, but now I'm getting an error that the signature of the two constructors are identical after erasure.I guess I'll use one of the other workarounds, then. Oh well.
--