Implicit Call Chain Calculation

Is there a way to understand the whole implicit chain (and I'm interested in all implicit views). I use IntelliJ Idea, but I'm looking for any way to do this, even if I have to work with a different IDE. (and I wonder if REPL will help me with this)

For example, I write a gt b where gt comes from scalaz . And I want to know:

  • Which implicit instance of Order was used
  • What type of styles was used (I know the answer in this particular case - itโ€™s easy in scalability, but in general sometimes itโ€™s not always so obvious)
  • The whole chain in which a gets the gt method. In this specific example, I know that the ToOrderOps trait was used, but, in general, I don't know this, and I also canโ€™t understand how ToOrderOps was imported.
+5
source share
1 answer

Using the Scala reflection API in a REPL is usually a good way to start an exploration like this:

 scala> import scala.reflect.runtime.universe.reify import scala.reflect.runtime.universe.reify scala> import scalaz._, Scalaz._ import scalaz._ import Scalaz._ scala> println(reify(1 gt 2)) Expr[Boolean](Scalaz.ToOrderOps(1)(Scalaz.intInstance).gt(2)) scala> println(reify("a" gt "b")) Expr[Boolean](Scalaz.ToOrderOps("a")(Scalaz.stringInstance).gt("b")) 

ToOrderOps here is a method, not a sign, and Scalaz means you see it because scalaz.Scalaz mixes in ToOrderOps , so I think this approach applies to all three of your points.

+18
source

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


All Articles