6

Is there any way how can I figure out the whole implicit chain (and I am interested in all of the implicit kinds). I'm using IntelliJ Idea, but I'm searching for any way to do that, even if I have to work with another IDE. (and I'm wondering whether REPL can help me with that)

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

  1. Exactly what implicit instance of Order was used
  2. What typeclass was used (I know the answer in this particular instance - it's easy in scalaz, but in general sometimes it not always that obvious)
  3. Whole chain how a received a method gt. For this particular example, I know that ToOrderOps trait was used, but in general I may not know that and I also can't figure out how ToOrderOps was imported.
Archeg
  • 8,364
  • 7
  • 43
  • 90
  • Looking at @stew's previous [answer](http://stackoverflow.com/a/34735993/409976), maybe you want [reify](https://gist.github.com/kevinmeredith/396cea7839fababa7e2a)? – Kevin Meredith Jan 20 '16 at 15:25

1 Answers1

20

Using the Scala reflection API in the REPL is usually a good way to start this kind of investigation:

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"))

The ToOrderOps here is a method, not the trait, and the Scalaz indicates that you're seeing it because scalaz.Scalaz mixes in the ToOrderOps trait, so I think this approach addresses all three of your points.

Travis Brown
  • 138,631
  • 12
  • 375
  • 680