我如何知道 Scala 函数的类型

How do I know the type of a scala function

我想知道 repl 中 scala 函数的类型。在 Haskell 中是 :t,谁能说出它在 scala 中的等价物?

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

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

如果您有一个现有值并想知道它的类型,您可以使用 :type

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

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

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