HaloO,
I'm very puzzled about what is meant by type and class in Perl6. In the sort ruling http://groups-beta.google.com/group/perl.perl6.language/msg/1eb1ed4608f5604d we saw a system of types that allow to nicely dispatch into different version of &sort. OTOH every class or role name can serve the same purpose. Built-in value types like Str and Int seem to be auto-coercive instead of MMD, in particular when playing together with dedicated operators like binary '+' versus '~'. And how does all this combine with the notion of context? I guess that basically influences method selection.
Take the following example:
# part 1 class Cyclic[uint $base] is Int { multi *postfix:<++> ( Cyclic[uint $base] $i ) returns Cyclic[uint $base] { return (($i as uint) + 1) % $base; } multi *infix:<+> ( Cyclic[uint $base] $x, Int $y ) returns Cyclic[uint $base] is symmetric { return abs( ($x as uint) + $y ) % $base; } ... }
# part 2 sub foo( Int $begin, Int $end ) { while $begin < $end { ... $begin++; # assumes Int axiom: $i + 1 > $i } }
#part 3 my Cyclic[8] $cyclic = 3;
foo( $cyclic, 10 ); # never returns?
Does the design intent to catch such "surprises"? E.g. by giving an error at the line 'class Cyclic[uint $base] is Int'? But how should the violation of an abstract property of Int be checked by the compiler? Can this just be remedied by source code review and human reasoning? Is there a chance for designers of classes like Int to prevent method overriding which violates some constraints? If yes, how are these constraints specified? my Cyclic[7] enum DayOfWeek <Mon Tue Wed Thu Fri Sat Sun>;
Another thing: does the above definition work together with enums?
my Cyclic[7] enum DayOfWeek <Mon Tue Wed Thu Fri Sat Sun>; my DayOfWeek $day = Fri; say "Fri = {$day}, Sat = {$day + 1}, Sun = {$day + 2}, Mon = {$day + 3}";
Does that say "Fri = Fri, Sat = Sat, Sun = Sun, Mon = Mon"?
Regards, -- TSa (Thomas Sandlaß)