On Thu, Oct 06, 2005 at 17:44:10 -0600, Luke Palmer wrote:
> Autrijus convinced me that we have to really nail down the semantics
> of type annotation without "use static".   Let's first nail down what
> I meant by "semantics" in that sentence.  Basically, when do various
> things get checked?  Run time or compile time (not coercion; I have a
> proposal for that coming).
> Oh, I'm asking p6l here, not Larry in particular.  This part of the
> language is yet-undesigned, so some arguments one way or the other
> would be nice to hear.
> So we're in line one of a Perl program, with static typing/inference
> disabled (or at least inference *checking* disabled; perl may still
> use it for optimization).  When do the following die: compile time
> (which includes CHECK time), run time, or never?
>     my Array $a = 97;      # dies eventually, but when?
>     my Int   $b = 3.1415;  # dies at all?

Both die at compile time, because the user explicitly contradicted
him/herself. This is like saying

        my int = $x :: float;

since they're constants and their types are very well known.

>     sub foo (Int $arg) {...}
>     foo("hello");          # should die at the latest when foo() is called

Immediately, at compile time, for every caller of foo unless 'no
static' or whatever is active for that scope.

However, no inferencing is made - this is just 1 level deep.

>     sub bar (Int $arg --> Str) {...}
>     foo(bar(42));

Since --> is explicit I'm not sure if it means "infer this even if
we're not globally inferring".

I lean towards compile time error here since I think it would be
nice to have that, but there are some disadvantages.

Perhaps this should infer only in the lexical scope that 'sub bar'
was defined in, to make sure that error reporting does not confuse
naive users of the module that defines foo, without asking for
compile time inference.

>     sub static  (Code $code, Array $elems --> Array) {
>         [ $elems.map:{ $code($_) } ]
>     }
>     sub dynamic ($code, $elems) {
>         [ $elems.map:{ $code($_) } ]
>     }
>     static({ $_+1 }, dynamic("notcode", [1,2,3,4,5]));
>     dynamic("notcode", static({ $_+1 }, [1,2,3,4,5]));

This is only with full inferencing, either lexically enabled as a a
pragma (in the scope that invokes), or if enabled globally.

 ()  Yuval Kogman <[EMAIL PROTECTED]> 0xEBD27418  perl hacker &
 /\  kung foo master: /me does a karate-chop-flip: neeyah!!!!!!!!!!!!!!

Attachment: pgpZ0kQYyANwT.pgp
Description: PGP signature

Reply via email to