scala - Why does Numeric treat unary differently to binary? -


what's this?

import numeric.implicits._  def myadd[t: numeric](x: t, y: t) = x + y   // works myadd(1,2)  def myinc[t: numeric](x: t) = x + 1   // fails @ x: not find implicit value parameter num: scala.math.numeric[any] myinc(9) 

scala 2.10

something x+1 --> numeric+int?

so after looking @ http://www.scala-lang.org/api/current/#scala.math.numeric , seeing one , fromint, fiddle bit in repl , came with:

scala> def myinc[t: numeric](x: t) = x + implicitly[numeric[t]].fromint(1) myinc: [t](x: t)(implicit evidence$1: numeric[t])t  scala> myinc(9) res1: int = 10  scala> def myinc[t: numeric](x: t) = x + implicitly[numeric[t]].one myinc: [t](x: t)(implicit evidence$1: numeric[t])t  scala> myinc(9) res2: int = 10 

it not related being method 1 argument, instead on compiler inferring t type any.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -