On Wed, Oct 19, 2005 at 01:48:08PM +0200, TSa wrote:
: HaloO,
: Luke Palmer wrote:
: >It looks nicer if you use the indirect object form:
: >
: >    trans "string": [
: >        <h e> => "0",
: >    ];
: Given the right interpretation this just looks like
: a typed label selection in a multi method.
:   multi trans
:   {
:       Str $x: ...; return;
:       Int $x: ...; return;
:       ...; return;
:   }
: Is this definitional form supported? To me it nicely
: unifies the indirect object syntax---and postfix colon
: in general---with labels.

We would certainly not define a new syntax just for that.  But it could
easily fall out of something resembling Luke's tuple proposal in
conjuction with a switch, assuming we add signature matching:

    multi trans (*$_) {
        when :(Str $x) { ... }
        when :(Int $x) { ... }
        default        { ... }

give or take a bit of signature notation.  Maybe something with pointies:

    multi trans (*$_) {
        when -> Str $x { ... }
        when -> Int $x { ... }
        default        { ... }

but we'd have to tell "when" not to look for a second block after
evaluating its condition, and the pointy would have to be smart enough
to realize it was being passed a tuple/arg list and not just try to
bind it to the first parameter.  Personally, I think the situation
will arise seldom enough that special syntax is not warranted, and a
general sig match via the smart operator is sufficient.  Though that
approach also mandates a bit of kludginess to make sure the signatures
bindings persist across the block and no further.  Though maybe that
falls out naturally if we include optional arrow on case values and
assume an implicit *$_ as the when target:

    multi trans (*$_) {
        when *$_ -> Str $x { ... }
        when *$_ -> Int $x { ... }
        default            { ... }

In that case, the only oddity is that the selection of the case includes
the success of binding it to the argument.  And also the extra implied *
on the case argument to flatten the tuple.

This is also all subject to the notion that we might have types that
are essentially named type tuples, probably as cases in a union type.
In such cases you can match the type name against the entire tuple
and then bind the args without typing them:

    multi trans (Tree *$_) {
        when Leaf -> $x       { ... }
        when Node -> $x,$y,$z { ... }
        default               { !!! }

But I'm still working my way through oodles of possible syntaxes
for declarative tree types and parametric types, so don't quote
me on this.  And in general people will want to declare these as
separate subs unless they have some particular reason for wanting to
force evaluation order, which is somewhat suspect in the first place
if you're using declared tree types.


Reply via email to