There are three ways to write tuple expressions. The most general form is TUPLE(tree, ...)
:
scala> import treehugger.forest._, definitions._, treehuggerDSL._
import treehugger.forest._
import definitions._
import treehuggerDSL._
scala> TUPLE() // ()
[1m[34mres0[0m: [1m[32mtreehugger.forest.Tree[0m = Literal(Constant(()))
scala> TUPLE(REF("x")) // (x)
[1m[34mres1[0m: [1m[32mtreehugger.forest.Tree[0m = Apply(Ident(Tuple1),List(Ident(x)))
scala> TUPLE(LIT(0), LIT(1)) // (0, 1)
[1m[34mres2[0m: [1m[32mtreehugger.forest.Tree[0m = Apply(Ident(Tuple2),List(Literal(Constant(0)), Literal(Constant(1))))
The second way is to use UNIT
literal:
scala> UNIT // ()
[1m[34mres3[0m: [1m[32mtreehugger.forest.Literal[0m = Literal(Constant(()))
Finally, PAREN(tree, ...)
can also be used to write a tuple expression:
scala> PAREN(REF("x")) // (x)
[1m[34mres4[0m: [1m[32mtreehugger.forest.Tree[0m = Apply(Ident(Tuple1),List(Ident(x)))
Semantically speaking the actual scala.Tuple
n are formed only when two or more arguments are passed, but as a syntactic expression, PAREN
is just an alias to TUPLE
.