More Than Five
More Than Five

Reputation: 10429

Debuggin single lines in Scala

A single of code can achieve a lot in Scala.

def -(that: Nat) = if (that.isZero) this else throw new Error("negative number")

However, it is difficult to debug. Any tips?

Upvotes: 2

Views: 89

Answers (2)

Gene T
Gene T

Reputation: 5176

you can see output of compiler phases, i.e. the AST after desugarings with

scalac -Xprint:typer

scalac -Xprint-types (note hyphen, not colon)

The man page is a little confusing, there's no "typer" phase listed, but it works:

http://www.scala-lang.org/docu/files/tools/scalac.html

Compile time type tracing

Upvotes: -1

om-nom-nom
om-nom-nom

Reputation: 62835

Use scala worksheet. That's it: you'll get multiline REPL with your environment in which you can play with your code.

enter image description here Alternatively, just use REPL bundled with sbt (sbt console) with proper imports

Upvotes: 4

Related Questions