On Fri, 29 Mar 2013 13:56:08 +0100, bearophile <bearophileh...@lycos.com> wrote:

One handy tuple syntax in Haskell allows you to name both the items of a tuple and it whole:


void foo(t2@{int a, string b}) {
    // here a and b are tuple items and t2 is the whole tuple.
}
auto t1@{x, y} = {10, "hi"};
foo(t1);

I suggest instead this syntax:

auto {x, y} t1 = {10, "hi"};

It's closer to regular D syntax.


foreach (Float; {float, double, real}) { ... }

I think you meant to put a variable name there.

foreach (Type; {float, double, real}) { ... }

See it now?


- - - - - - - - - - - -

{c, $} = tup;   // Rewritten as: c = tup[0];

$ is used for array lengths, so it's not so good to overload it to mean "don't care" too.

Alternative syntaxes:

{c, $_} = tup;
{c, @} = tup;
{c, @_} = tup;
{c, $$} = tup;
{c, {}} = tup;
{c, {_}} = tup;
{c, $~} = tup;
{c, @~= tup;
etc.

... has been introduced to match zero or more elements for pattern matching
already. I see no reason not to use ... for this.

--
Simen

Reply via email to