Implicit conversion of a shared container for an implicit parameter in Scala

Is there any way to make this work? (Scala 2.8.1)

class A def f(implicit a: A) = 0 class Vendor[T](val v: T) implicit val vendor = new Vendor(new A) implicit def vendorToVal[T](implicit v: Vendor[T]) = vv f 

Error: "Implicit extension divergence for type A starting with vendorToVal"

This is due to Lift 2.2 dependency injection, the real code is as follows:

 class UserStore(implicit db: DbAccess) object DependencyFactory extends Factory { implicit val db = new FactoryMaker[DbAccess](Model) {} import db._ // implicit conversion would allow to remove this import implicit val userStore = new FactoryMaker[UserStore](new UserStore) {} } 

This question is related to: Is there a way to implicitly convert an implicit parameter to Scala?

+4
source share
2 answers

The problem is caused by the vendorToVal method - I observed the same behavior many times when I used implicit parameters in implicit parameterized parameters. Unfortunately, I did not find a simple and elegant glue in 2.8._.

Some interesting topics related to the topic:

+3
source

In Scala 2.9 trunk, you can do this:

 scala> class A defined class A scala> def f(implicit a: A) = 0 f: (implicit a: A)Int scala> scala> class Vendor[T](val v: T) defined class Vendor scala> implicit def value[T: Vendor] = implicitly[Vendor[T]].v value: [T](implicit evidence$1: Vendor[T])T scala> implicit val vendor = new Vendor(new A) vendor: Vendor[A] = Vendor@bbb2d0 scala> f res0: Int = 0 

A call to f will search for a value of type A and find the implicit value[A] , which requires a proof parameter of type Vendor[A] . It enables this vendor proof parameter.

I do not think that the implications were so powerful in 2.8.1.

+1
source

Source: https://habr.com/ru/post/1343381/


All Articles