[nem-en] Tuple indexing

Michal Moskal michal.moskal at gmail.com
Thu Feb 22 10:30:13 CET 2007


On 2/22/07, Vladimir Reshetnikov <v.reshetnikov at gmail.com> wrote:
> What about tuple indexing with non-constant index?
> There are scenarions, when it may be made type-safe.
> I mean
>
> module B {
>   Foo[T](x : T) : void { }
>   Bar(p : int) : void {
>     def tup = (1, 1.1, "a");
>     Foo(tup[p]);
>   }
> }
>
> as a shorthand for
>
> module B {
>   Foo[T](x : T) : void { }
>   Bar(p : int) : void {
>     def tup = (1, 1.1, "a");
>     match(p) {
>         | 0 => Foo(tup[0]);
>         | 1 => Foo(tup[1]);
>         | 2 => Foo(tup[2]);
>     }
>   }
> }
>
> IMO, it would be reasonable to allow such tuple indexing in an
> argument of polymorphic method.

You would still get (rightly) a warning about non-exhaustive matching here.

-- 
   Michał


More information about the devel-en mailing list