OK guys. I guess that's it; I can't do that... :( Thank you everyone anyway.
On 31 May 2012 21:17, Tom Switzer <
thomas....@gmail.com> wrote:
>
>
> On Thu, May 31, 2012 at 12:47 PM, Seyed H. HAERI (Hossein)
> <
hossei...@gmail.com> wrote:
>>
>> Hi Rahul,
>>
>> > (X, (Y, Z)*) is not a valid type. (You seem to be misunderstanding
>> > tuples, varargs, and parameter lists.)
>>
>> I got his point on this. But, that doesn't solve my problem. See below.
>>
>> > You can (and should) change your design as Erik suggested.
>> >
>> > case class X(x: X, yzs: Seq[(Y, Z)])
>> > implicit def tuple2x(pair: (X, Seq[(Y, Z)]) = X(pair._1, pair._2)
>> >
>> > If you still want the varargs support for X's construction, write a
>> > factory
>> > method for that.
>> >
>> > object X {
>> > def apply(x: X, yzs: (Y, Z)*) = X(x, yzs.toSeq)
>> > }
>> >
>> > This way you can have your cake and eat it too.
>>
>> No, that's wrong. I have a function f(T, X): T that I would like to
>> have the option of calling it like f(t, (x, y1 -> z1, y2 -> z2)). This
>> call fits perfectly in the domain I'm programming in. But, changing
>> f's signature to accommodate a call like f(t, x, y1 -> z1, y2 -> z2)
>> doesn't. Your current design doesn't facilitate my desired function
>> call. Regardless of my trials so far, is there any way to achieve that
>> at all?
>
>
> Well, no, because the way you are calling f is with 2 arguments. You want
> the 2nd argument to have variable number of elements, but are unwilling to
> wrap it in a Seq or List or something and you will only accept bare
> parenthesis. Scala will see the parenthesized "list" and treat it as a
> n-tuple (n is the number of elements in the 2nd argument). That's because
> what you are writing is a short-hand syntax for a tuple. You can't
> arbitrarily nest variable arguments like you want to do. So, no, you can't
> do what you want.
>
> However, as Som Snytt pointed out, you may be able to make use of the tuple
> syntax you are using. You can either override f for Tuple2 through to
> Tuple22, or you can use some implicit conversions to convert (A, A, ..., A)
> to a Seq[A].
>
>>
>>
>> TIA,
>> --Hossein
>>
>>
>> --------------------------------------------------------------------------------------------------------------
>>
>> Seyed H. HAERI (Hossein)
>>
>> Research Assistant
>> Institute for Software Systems (STS)
>> Technical University of Hamburg (TUHH)
>> Hamburg, Germany
>>
>> ACCU - Professionalism in programming -
http://www.accu.org/
>>
>> --------------------------------------------------------------------------------------------------------------
>
>
--