Luke Palmer wrote:
    class CodeProxy {
        has Code $.code is rw;
        sub call ($a) {
            $.code($a);
        }
    }

This is valid Perl 6,

Hmm, a sub in a class? I guess that should be a method. OTOH a class is just a funny module, so might be OK. But that is the syntax realm.


and anyone who says otherwise (because of type
signatures) is changing the Perl philosophy too much to be taken
seriously.  Now, tell me at compile time whether the call inside `call`
is valid.

Ups, before we start talking past each other: I think a type system is just a tool that reminds you to your declarations. No declarations, no reminder, it's that simple. I would like the typing of $.code as Code to be necessary to apply the .() invocation operator on it. The rest is deferred to runtime if that is what you want.

And I'm completly unsure how much parrot and/or perl revert back into
compile state when you bring in new source code at runtime. Or how
much load time activity is needed for a byte code file.

The question if instances of DoubleCodeProxy are subtypes of instances
of CodeProxy boils down to the question if ($) <: ($, +$) with <: beeing
the subtype relation. Is that the right siglet syntax? Since named-only
parameters are optional the relation holds. This subtype relation allows:

my CodeProxy $cp = DoubleCodeProxy.new; # needs DoubleCodeProxy <: CodeProxy

$cp.code = sub ($x, +$y = "unknown") { say "x = $x, y = $y" };

$cp.call( "first", b => "second" ); # prints "x = first, y = second"
$cp.call( "one" );                  # prints "x = one, y = unknown"

$t = $cp.code;

$cp.code = sub () { say "void" };  # no problem, type is Code
$cp.call( "X" ); # gives runtime error on closure in $.code

$cp.code = $t;

$cp.call(); # compile error: too few args
$cp.call( 1, 2 ); # compile error: too many positional args
$cp.blahh( 23 ); # compile error/warning: no such method declared

method CodeProxy::blubber(: $z ) { ... }

$cp.blubber( 42 ); # could die on ... at runtime if no .blubber autoloaded

$cp.call( 1|2|3 ); # autothreads??? I leave that to Damian :)
--
TSa (Thomas SandlaÃ)



Reply via email to