On 10/6/05, Luke Palmer <[EMAIL PROTECTED]> wrote: > 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?
This is just my opinions as a Perl programmer in the trenches. I would expect Typed variables to auto-coerce themselves, but not impose fatality. Predictable auto-coercion would be nifty in quick-and-dirty programs. Ignore my advice at will -- nobody's required to use Types in their own code, so there's no need for them to be universally valuable. However, since I expect builtins and all standard functions to have fully declared Type signatures, consider how these decisions would affect _every_ program, before ordering the summary execution of everyone's poor little Perl script. > my Array $a = 97; # dies eventually, but when? Runtime -- cannot coerce Int value to Array > my Int $b = 3.1415; # dies at all? Doesn't die, $b == 3. Int scalars should coerce anything which can be &prefix:<+>'d. > sub foo (Int $arg) {...} > foo("hello"); # should die at the latest when foo() is called $arg should be undef but Exception::InvalidInteger("Str value 'hello' cannot be coerced to an Int at $?LINE") > sub bar (Int $arg --> Str) {...} > foo(bar(42)); If bar returns a Str ~~ /<Perl6::Grammar::Int>/, it gets coerced; otherwise, undef but Exception > 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])); die "Str value 'notcode' cannot be called as a Sub reference -- have you asked Larry how to make a symbolic function call, lately?"; > dynamic("notcode", static({ $_+1 }, [1,2,3,4,5])); Same. Just my 2ยข Ashley Winters