在Scala中检查函数类型
在Haskell中,我可以使用在Scala中检查函数类型,scala,Scala,在Haskell中,我可以使用:t在ghci中检查函数的类型: Prelude> :t odd odd :: Integral a => a -> Bool 这表示函数odd采用Integral类型并返回Bool。Scala有类似的功能吗?在Scala REPL中实际上是完全相同的: scala> def odd(x : Int) = x % 2 != 0 odd: (x: Int)Boolean scala> :t odd (x: Int)Boolean 这
:t
在ghci
中检查函数的类型:
Prelude> :t odd
odd :: Integral a => a -> Bool
这表示函数
odd
采用Integral
类型并返回Bool
。Scala有类似的功能吗?在Scala REPL中实际上是完全相同的:
scala> def odd(x : Int) = x % 2 != 0
odd: (x: Int)Boolean
scala> :t odd
(x: Int)Boolean
这是最近增加的吗?我在scala 2.8.1中没有看到它。@VladtheImpala REPL在不断发展。@VladtheImpala我也因为同样的原因感到困惑;它不在Scala2.8.1中,但在Scala2.9.1中。嗯