I need to define a class of type Field as follows:
trait Field[A] {
A class of type Numeric also provides zero and one methods.
I want every class that a Numeric instance is available to use wherever a class with a Field instance is required. For example, the following should work:
def func[F: Field](f: F) = println(f) func(2)
Could you suggest how to do this? I tried the following, but this did not work:
scala> implicit def numericToField[N](n: Numeric[N]) = new Field[N] { | def zero = n.zero | def one = n.one | } numericToField: [N](n: Numeric[N])java.lang.Object with Field[N] scala> def func[F: Field](f: F) = println(f) func: [F](f: F)(implicit evidence$1: Field[F])Unit scala> func(2) <console>:12: error: could not find implicit value for evidence parameter of type Field[Int] func(2) ^
source share