Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. abstract class Op[@specialized Left, @specialized Right] {
  2. @specialized
  3. type Result
  4.  
  5. def r: Numeric[Result]
  6. def times(left: Left, right: Right): Result
  7. }
  8.  
  9.  
  10. object Op {
  11.  
  12. implicit object IntDoubleOp extends Op[Int, Double] {
  13. type Result = Double
  14. val r = implicitly[Numeric[Double]]
  15. def times(left: Int, right: Double): Double = left * right
  16. }
  17. }
  18.  
  19.  
  20. object calc {
  21.  
  22. def dot[@specialized Left, @specialized Right](xs: Array[Left], ys: Array[Right])
  23. (implicit op: Op[Left, Right]): op.Result = {
  24. var total = op.r.zero
  25. var index = xs.length
  26. while(index > 0) {
  27. index -= 1
  28. total = op.r.plus(total, op.times(xs(index), ys(index)))
  29. }
  30. total
  31. }
  32. }
  33.  
  34. test.scala:31: error: type mismatch;
  35. found : op.Result
  36. required: op.Result
  37. total
  38. ^
  39. one error found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement