4

I often find a neat solution to a problem by using Scalaz pimps. Usually the solution works like

import scalaz._
import Scalaz._
foobar frobnicate quux
// magic

Now, I would like to be able to see what implicits I have actually used to add to my Foobar a frobnicate method. In this way I can make a more refined import and learn something new about the tool I have implicitly used.

Is there some way to find out what implicit conversions the compiler actually used to compile some expression?

Andrea
  • 20,253
  • 23
  • 114
  • 183
  • Not exactly what you wanted but you can enlist all implicits in the current scope with `:implicits` – om-nom-nom Sep 19 '12 at 16:21
  • I know, but the problem is that if I import Scalaz._ I get *a lot* of implicits and it is just not practical to browse them all... – Andrea Sep 19 '12 at 16:23
  • 1
    Related: http://stackoverflow.com/questions/3179415/is-there-a-systematic-way-to-discover-which-implicit-defs-are-in-scope-and-whic – retronym Sep 20 '12 at 06:00
  • 1
    http://stackoverflow.com/questions/9999664/how-to-examine-implicit-rich-conversions-and-implemented-traits-in-the-repl/10001117#10001117 – retronym Sep 20 '12 at 06:02

2 Answers2

5

You can also see the fully expanded version of your code using the -Xprint:typer option to scalac. In a sbt project, one can add the line

scalacOptions += "-Xprint:typer"

to build.sbt and see the result with the compile commmand.

(taken from the answer linked by retronym)

Andrea
  • 20,253
  • 23
  • 114
  • 183
3

The scala plugin for eclipse shows implicits used. A small icon appears at to the left of the line where it is used. I think Intellij has a similar feature.

Kim Stebel
  • 41,826
  • 12
  • 125
  • 142
  • 1
    Nice, but I am noit using an IDE, and I don't know if it is worth the hassle of configuring and learning one for just this... – Andrea Sep 19 '12 at 16:32
  • actually all you need to do is download and extract it: http://typesafe.com/stack/scala_ide_download – Kim Stebel Sep 19 '12 at 16:34
  • I have tried, but it crashes when I try to change workspace to a given folder containing my Play project – Andrea Sep 19 '12 at 16:54
  • so choose a different folder, use sbt eclipse and import your project as an "existing eclipse project" – Kim Stebel Sep 19 '12 at 17:02
  • Cool! :-D Thank you for the hint, it was easier than I thought! – Andrea Sep 19 '12 at 17:06