我如何知道scala函数的类型

时间:2017-07-19 06:18:46

标签: scala read-eval-print-loop

我想知道repl中scala函数的类型。在Haskell中它是:t,任何人都可以告诉它在scala中的等价物吗?

1 个答案:

答案 0 :(得分:8)

有两种方法可以了解。输入表达式后,它会告诉类型:

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

如果您有现有值并想知道其类型,请使用:type

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

或者正如其他人所说,:t也与Haskell类似:

scala> :t f
Int => (Int => Int)
相关问题