program epson sx115
adjustment program epson sx115 for windows
Category:Printers
Category:EpsonQ:
Typeclass instanceof error in scala
I have following definition
trait Calculator[A]{
def add[B](x: A, y: B)(implicit ev: Eq[B]): A = x + y
def subtract[B](x: A, y: B)(implicit ev: Eq[B]): A = x - y
def mul[B](x: A, y: B)(implicit ev: Eq[B]): A = x * y
def divide[B](x: A, y: B)(implicit ev: Eq[B]): A = x / y
}
object Calculator {
implicit def toCalcOps(calc: Calculator[Int]): Int => Int = {
case i:Int => calc.add(i,i)(i.isInstanceOf[Int])
}
}
I wanted to try to create a Calculator instance by doing
object Calculator {
implicit def toCalcOps(calc: Calculator[Int]): Int => Int = {
case i:Int => calc.add(i,i)(i.isInstanceOf[Int])
}
}
then I can use it like following
object Test extends App {
println(Test.toCalcOps(new Calculator[Int]{}))
println(Test.toCalcOps(5))
}
when I run this code I get following error
[error] /home/abc/workspace/Test.scala:6: error: type mismatch;
found : Int => Boolean
required: A => Boolean
case i:Int => calc.add(i,i)(i.isInstanceOf[Int])
Why I am getting this error. Can someone explain me this.
A:
Your code is not compileable because you are attempting to create an instance of Calculator[Int], which is ambiguous, since there is no implicit conversion from Int to Calculator[Int].
In general, you have to be explicit in the implicit class definition: ac619d1d87
Related links:
https://cy.unionfighting.co.uk/profile/RenaultDialogys48Multilingual-sevaud/profile
https://melaninterest.com/pin/trilogia-la-brujula-dorada-libros-pdf-free/
https://www.cakeresume.com/portfolios/patwari-course-books-in-urdu-pdfl-jemglyn
https://melaninterest.com/pin/citroen-service-documentation-backup-2007-full-version-rozaby/
コメント