-2

My scala repl is not showing the logs on the screen as some books and forums seem to suggest. I am on scala 2.12.1. My scala repl when I try below syntax

scala> def sum(a:Int, b:Int) = a+ b
sum: (a: Int, b: Int)Int

Should show as below

scala> val fun2 = sum _
fun2: (Int, Int) => Int = <function2>

But it is showing as below:

scala> val fun2 = sum _
fun2: (Int, Int) => Int = $$Lambda$1623/2005055216@13bdf19

It is not showing the trait like <function2> etc. How do I fix this?

jwvh
  • 50,871
  • 7
  • 38
  • 64
curiousengineer
  • 2,196
  • 5
  • 40
  • 59

2 Answers2

0

I am assuming this is due to the way Scala 2.12 now SAM converts Scala functions SAM interfaces. If you want to see the type of an expression, prepend :t to the declaration:

scala> :t val fun2 = sum _
(Int, Int) => Int
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
0

The Scala 2.12 type checker accepts a function literal as a valid expression for any Single Abstract Method (SAM) type, in addition to the FunctionN types from standard library. This improves the experience of using libraries written for Java 8 in Scala.

scala> val runRunnable: Runnable = () => println("Run!")

runRunnable: Runnable = $$Lambda$1073/754978432@7cf283e1

scala> runRunnable.run() Run!

tom
  • 1
  • 1