4

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)

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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

This works:

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

Scala is great!

Comments

1

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)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.