Re: Tuples, Generics, and compiler bugs, oh my!

Daniel Bonniot <[email protected]> Mon, 11 Jul 2005 11:03:35 +0200
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
> Ok, I'm using the following:
> 
> String toString( (int t, int u))
> {
>   
>   return "HELLO: (" + t.toString() + "," + u.toString() + ")";
> }
> 
> <T,U> String toString(( T t, U u )) = "(" t "," u ")";
> 
> void main(String[] args)
> { 
>   int a = 1;
>   int b = 2;
>   println((a,b).toString()); 
> }
> 
> and that prints:
> [I@df6ccd

Are you sure you recompiled before running? I just tried it, and I get the 
expected output:
HELLO: (1,2)

> Yes I was using 0.9.10 which I believed to be current, as it is still linked 
> to from the installation page for the rpm, even though 0.9.11 is on 
> sourceforge.

Right, my mistake.

> Just explain that:
> (int i, String s, Cat c, int j)
> Is actually shorthand for:
> (int i, (String s, (Cat c, int j)))

Hey, looks like Lisp! ;-)


> Then it would be easy to write function for arbitrary length tuples:
> <T> void Print((int i, String s, ?T ext = null)) = System.out.println(i s 
> Print(ext)); //Would get picked first because it is more specific.

Yes, it's possible. The benefit over my solution is that it gives more static 
typing information. On the other hand I think it makes it impossible to write 
a method that accepts only couples with any second component. This could be 
solved by using, say, "..." as a type to mean "the rest of a tuple".

I would think it might be sufficient in practice to match the first element of 
the tuple, and receive the rest as a second argument.

In any case, this represents quite a lot more work than the nice.lang.Tuple 
solution (which could coexist in the long run). Would that one be good enough 
for you now? Or would somebody want to try to implement this proposal?

Cheers,

Daniel


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP, 
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar