Rod Adams wrote:
And then internally dispatch on what is defined and undefined.

Why all that burden if Perl 6 is getting a strong type system, that can do the sub selection and compile in dynamic dispatch if needed?

I imagine:

multi sub cos( Num +$angle ) returns Num where { -1.0 <= $_ <= 1.0 }

class Radians is Num
{

}
class Degrees is Num
{
    postfix:<°> ( Num $x ) { return  $x * PI  / 180 }

    multi sub cos( Degrees +$angle ) returns Num where { -1.0 <= $_ <= 1.0 }
    {
       return cos( $angle  * PI  / 180 );
    }
}

Note that cos(30°) calls &cos<Num> while &cos<Degrees> is used for
cases like:

Degrees $angle = 30.0;

if cos $angle > 2.0 { print "HaloO typechecker!" }


And I still wonder if the ones without '°' on their keyboard could directly call 'cos<Degrees> $angle'.


Regards, -- TSa (Thomas Sandlaß)



Reply via email to