in reply to Re^8: rough approximation to pattern matching using local (Multi Subs)
in thread rough approximation to pattern matching using local
| »»» This post is about the immature Perl 6, not the rock solid Perl 5 ««« |
If Perl6 is to retain scalars; but people write their modules using Ints & Strs etc. for efficiency; then it either forces their users to also use Ints & Strs etc. or multi-subs will have to use runtime resolution.
No. (Or, rather, the user doesn't need to know they're using Ints, Strs, etc.)
multi sub a ( Int $, Int $ ) {} my ($foo, $bar) = 1, 2; say $foo.VAR; says 'Any' say $foo.WHAT; # says '(Int)' a($foo, $bar); # call is resolved at compile time
No type is declared for the container $foo. So it's `of` type defaults to Any. This serves as a constraint on what can be assigned to $foo -- anything that is of type Any or a subtype (anything but Junction or Mu).
The type of the contained value is distinct. In this case the compiler infers that it's an Int. An Int is a subtype of Any so the assignment is OK.
Both of these types are known at compile time.
The type info available at compile-time includes:
Even if the coder calls multisubs without adding type info to their args the call will still be resolved at compile-time if there's enough type info available at compile-time.
»ö« . o O ( "the celebrity tell-all of the Perl-6 cult?" )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: rough approximation to pattern matching using local (Multi Subs)
by BrowserUk (Patriarch) on Feb 09, 2015 at 05:47 UTC | |
by raiph (Deacon) on Feb 09, 2015 at 08:48 UTC | |
by BrowserUk (Patriarch) on Feb 09, 2015 at 12:45 UTC | |
by raiph (Deacon) on Feb 10, 2015 at 03:45 UTC | |
by BrowserUk (Patriarch) on Feb 10, 2015 at 04:28 UTC |