0

Is there in SBT a way to display the data type of a Scala method?

In GHC (Haskell) we can do:

:t something

Is there any similar command in SBT?

2 Answers 2

1

If you call the method with _, you'll see the arguments and the return type of the resulting partially applied method:

scala> def helloWorld(i: Int): Option[Int] = { Some(i) }
helloWorld: (i: Int)Option[Int]

scala> helloWorld _
res0: Int => Option[Int] = <function1>
1
  • It is actually called partially applied method
    – om-nom-nom
    Mar 29, 2013 at 20:20
1

No, sbt is only a build tool. You can however use the same command :t in the scala REPL. You can also start the scala REPL from sbt with your current environment with the sbt command console. As alexwriteshere already said, you have to partially apply methods to get their type.

Some examples:

scala> def foo(x: Int, y: Int): Int = x+y
foo: (x: Int, y: Int)Int

scala> :t foo _
(Int, Int) => Int

scala> :t 3
Int

scala> :t List(1,2,3)
List[Int]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.