math - Sum or Product of Rationals with Spire (how to get a scala.Numeric) -


i thought should straight forward:

import spire.math.rational  val seq  = vector(rational(1, 4), rational(3, 4)) val sum  = seq.sum      // missing: scala.numeric val prod = seq.product  // missing: scala.numeric 

i guess question of bringing right stuff implicit scope. import?

i can see in order rationalisnumeric, have this:

import spire.math.numeric._ implicit val err = new approximationcontext(rational(1, 192)) implicit val num = rationalisnumeric 

but gives me spire.math.numeric. try additionally:

import spire.math.compat._ 

but no luck...

all that's needed evidence of spire.math.compat.numeric[rational]:

import spire.math._  val seq = vector(rational(1, 4), rational(3, 4)) implicit val num = compat.numeric[rational]  // ! seq.sum     // --> 1/1 seq.product // --> 3/16 

Comments