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

Tom Kaitchuck <[email protected]> Mon, 11 Jul 2005 22:51:32 -0700
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
On Monday 11 July 2005 2:03 am, Daniel Bonniot wrote:
> > 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?

If that is easy to implement then yes, it would be useful. However ultimately 
I think we should do something like one of the mentioned ideas. (Perhaps a 
generic tuple could be "(<A>,<B>)" or abbreviated somehow.)


-------------------------------------------------------
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