You could create additional method for sum of Short
.
There is already such methods in scala
in Numeric
type class:
import scala.math.Numeric
val ns = implicitly[Numeric[Short]]
val s = 1: Short
ns.plus(s, s)
// Short = 2
ns.times(3, 2)
// Short = 6
In case you can abstract over Short
type you could use +
method from Numeric.Implicits
like this:
import Numeric.Implicits._
def traverse[T: Numeric](tree: Tree[T], level: T, pos: T) {
val one = implicitly[Numeric[T]].one
buf(level) += tree
var pos: T = -one
tree.getChildrenAsList.iterator().foreach { z =>
pos += one
traverse(z, level + one, pos)
}
}
You could also use |+|
from scalaz
as replacement for +
:
import scalaz._, Scalaz._
s |+| s
// Short = 2