Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know the type of a scala function

I would like to know the type of a scala function in repl. In Haskell it is :t, can anyone tell what it's equivalent in scala?

like image 722
Srinivas Avatar asked Jul 19 '17 06:07

Srinivas


1 Answers

There are two ways to know. Once you type in the expression, it tells the type:

scala> val f: Int => Int => Int = a => b => a + b
f: Int => (Int => Int) = $$Lambda$1143/444402847@2b1a901d

If you have an existing value and want to know its type, you use :type

scala> :type f
Int => (Int => Int)

Or as others mention, :t also works similar to Haskell:

scala> :t f
Int => (Int => Int)
like image 77
Yuval Itzchakov Avatar answered Oct 02 '22 09:10

Yuval Itzchakov