# non/spire

Added spire.math.compat package for implicit conversions.

```The spire.math.compat package contains implicit conversion methods for
scala.math types: Equiv, Ordering, Integral, Fractional, and Numeric.

The expected usage pattern is:

// 'sorted' uses scala.math.Ordering
def orderingTest {
import spire.math.compat.ordering
def example[A: Order](ns: List[A]) = ns.sorted
}

// 'sum' uses scala.math.Numeric
def numericTest {
import spire.math.compat.numeric
def example[A: Numeric](ns: List[A]) = ns.sum
}

Unfortunately, the fractional, integral, and numeric methods cause ambiguous
implicit problems, so trying to import all of them at once doesn't work.```
1 parent 6796f8d commit 5eac52f79cd3d5317fc2a6faac85f0d17fce39bb committed Nov 4, 2012
Showing with 39 additions and 40 deletions.
1. +0 −40 src/main/scala/spire/math/ScalaWrappers.scala
2. +39 −0 src/main/scala/spire/math/compat.scala
 @@ -2,7 +2,6 @@ package spire.math import spire.algebra._ - trait ScalaEquivWrapper[A] extends scala.math.Equiv[A] { def eq: Eq[A] @@ -62,42 +61,3 @@ with scala.math.Integral[A]{ def quot(x:A, y:A): A = structure.quot(x, y) def rem(x:A, y:A): A = structure.mod(x, y) } - - -/** - * Provides methods for creating `scala.math` typeclasses from Spire - * typeclasses. - */ -object ScalaMath { - def equiv[A: Eq] = new ScalaEquivWrapper[A] { - val eq = Eq[A] - } - - def ordering[A: Order]: scala.math.Ordering[A] = new ScalaOrderingWrapper[A] { - val order = Order[A] - } - - def numeric[A: Ring: ConvertableFrom: Signed: Order] = { - new ScalaNumericWrapper[A] { - val order = Order[A] - val structure = Ring[A] - val conversions = ConvertableFrom[A] - val signed = Signed[A] - } - } - - def fractional[A: Field: ConvertableFrom: Signed: Order] = new ScalaFractionalWrapper[A] { - val order = Order[A] - val structure = Field[A] - val conversions = ConvertableFrom[A] - val signed = Signed[A] - } - - def integral[A: EuclideanRing: ConvertableFrom: Signed: Order] = new ScalaIntegralWrapper[A] { - val order = Order[A] - val structure = EuclideanRing[A] - val conversions = ConvertableFrom[A] - val signed = Signed[A] - } -} -
 @@ -0,0 +1,39 @@ +package spire.math + +import spire.algebra._ + +object compat { + implicit def equiv[A: Eq] = + new ScalaEquivWrapper[A] { + val eq = Eq[A] + } + + implicit def ordering[A: Order] = + new ScalaOrderingWrapper[A] { + val order = Order[A] + } + + implicit def fractional [A: Field: ConvertableFrom: Signed: Order] = + new ScalaFractionalWrapper[A] { + val order = Order[A] + val structure = Field[A] + val conversions = ConvertableFrom[A] + val signed = Signed[A] + } + + implicit def integral[A: EuclideanRing: ConvertableFrom: Signed: Order] = + new ScalaIntegralWrapper[A] { + val order = Order[A] + val structure = EuclideanRing[A] + val conversions = ConvertableFrom[A] + val signed = Signed[A] + } + + implicit def numeric[A: Ring: ConvertableFrom: Signed: Order] = + new ScalaNumericWrapper[A] { + val order = Order[A] + val structure = Ring[A] + val conversions = ConvertableFrom[A] + val signed = Signed[A] + } +}