Is it possible to add some magic construct around a Scala expression so that it prints the type during compilation? E.g. have some class, magic function, meta programming type, which does:
val i = 1
Some(11).map(Trace(_ + 1))
// compile
// prints: Int
Not exactly, but how 'bout this
$ cat Test.scala
def Trace[T] = identity[T] _
val i = 1
Some(11) map {x => Trace(x + 1)}
$ scala -Xprint:typer Test.scala 2>&1 | egrep --o 'Trace\[.*\]'
Trace[T >: Nothing <: Any]
Trace[Int]
The first Trace comes from the definition of Trace and can be ignored. The same parameter (-Xprint:typer) works with scalac, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With