views:

68

answers:

3

I need something like this:

class Node (left : Node*, right : Node*)

I understand the ambiguity of this signature.

Is there a way around it better than the following?

class Node (left : Array[Node, right : Array[Node])
val n = new Node (Array(n1, n2), Array(n3))

Maybe some kind of separator like this?

val n = new Node (n1, n2, Sep, n3)
+1  A: 

I dont beleive you can have multiple varargs. You maybe could do something like

class Node(left: Node*) {
  def apply(right: Node*) = ...

and then you can create new Node(n1,n2)(n3)

Jackson Davis
+4  A: 

This works:

class Node (left : Node*) (right : Node*)

Scala is great!

Łukasz Lew
+5  A: 

You can have multiple argument lists, each of which may have (or just be) one repeated-args parameter:

scala> def m1(ints: Int*)(strs: String*): Int = ints.length + strs.length
dm1: (ints: Int*)(strs: String*)Int

scala> m1(1, 2, 3)("one", "two", "three")
res0: Int = 6

I ran this in the Scala 2.8 REPL. I don't know a reason it wouldn't work in 2.7, offhand.

Randall Schulz
@Łukasz Lew: I was but 9 seconds behind you!
Randall Schulz
So I will give you the great green tick of answer :)
Łukasz Lew