Thank you for replying.
my Int $age = 40;
$age = "old";
That will generate a
compile-time
error. (Because the "old" bit is a string literal which is interpreted in this case as being of nominal type Str which isn't compatible with the nominal type Int).
Do you have any tips for me on how to make it clearer on the page I linked that this is compile-time checking? Or, more simply, did you just not believe the "compile-time" comment on the page I linked or did you just miss it, perhaps because it's "commented out"? Would it make sense for me to incorporate some of what I write below?
----
Perl 6 supports more than just static nominal typing. You can add arbitrary constraints:
my Int $school-age where 5..18 = 40;
The code that comes after the 'where' (the '5..18' bit) can be arbitrary code. It is tested against any value that would be assigned to the $school-age variable.
Most folk will just like the convenience of this construct and won't care whether it results in a check at compile-time or run-time.
But some will care.
So, while nominal typing is a compile-time checking affair, what about these arbitrary constraints? Do these result in checks at compile-time or run-time? Well, it depends.
Key quotes from the relevant language design doc[1] are:
> A where clause is considered static if it can be applied to the types to the left of it at compile time to produce a known finite set of values.
The line of code we're looking at:
my Int $school-age where 5..18 = 40;
can clearly be reduced to the set of integers from 5 to 18. And the compiler code to successfully make that analysis is fairly straight-forward, so it could fairly easily be implemented in Rakudo today.
However, for 6.0.0 (by which I mean the suite of 35K+ tests that are supposedly going to reach beta status by September and the Rakudo compiler that is supposedly going to reach gold status by the end of the year) there's this:
> for 6.0.0 any structure type information inferable from the where clause will be ignored
In other words, the line we've been looking at with the `where` clause will result in a run-time check for 6.0.0.
----
[1] http://design.perl6.org/S12.html#Multiple_constraints