Hello,
While re-factoring some code I realized that a local implicit is being substituted
by Predef’s identity. More concretely I have the local definitions:
val defaultB = false
implicit def isDefault(v : Double) : Boolean = v.isNaN
implicit def isDefault(v : Int) : Boolean = v == defaultI
def isDefault(v : Boolean) : Boolean = v == defaultB
implicit val conforms = (v : Boolean) => isDefault(v)
I have a class that uses these implicitly:
sealed trait Algorithm {
def convert[T](command: String, value : T)(implicit check : (T) => Boolean) : List[String] = {
if (check(value)) List() else List(command, value.toString)
}
}
When searching for a solution I found: https://issues.scala-lang.org/browse/SI-2811
Accordingly as shown above I have redefined conforms
using a def
and val
and
declaring the function as shown above or as a standard function. However when I
try to use this in the class:
case class General(shrinking: Boolean = defaultB) extends Algorithm {
val shrinking_ : List[String] = convert("-h", shrinking)
}
I get the error:
[error] adw/src/main/scala/com/github/cjlin1/SVM.scala:248: ambiguous implicit values:
[error] both method $conforms in object Predef of type [A]=> <:<[A,A]
[error] and value conforms in object SVM of type => Boolean => Boolean
[error] match expected type Boolean => Boolean
[error] val shrinking_ : List[String] = convert("-h", shrinking)
Can anyone tell me how I can ensure that my version of the function is used?
TIA,
HF