Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Op[@specialized Left, @specialized Right] {
- @specialized
- type Result
- def r: Numeric[Result]
- def times(left: Left, right: Right): Result
- }
- object Op {
- implicit object IntDoubleOp extends Op[Int, Double] {
- type Result = Double
- val r = implicitly[Numeric[Double]]
- def times(left: Int, right: Double): Double = left * right
- }
- }
- object calc {
- def dot[@specialized Left, @specialized Right](xs: Array[Left], ys: Array[Right])
- (implicit op: Op[Left, Right]): op.Result = {
- var total = op.r.zero
- var index = xs.length
- while(index > 0) {
- index -= 1
- total = op.r.plus(total, op.times(xs(index), ys(index)))
- }
- total
- }
- }
- test.scala:31: error: type mismatch;
- found : op.Result
- required: op.Result
- total
- ^
- one error found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement