Type-based dispatch
Type constraints in signature used to select sub:
multi sub double(Num $x) { return 2 * $x; } multi sub double(Str $x) { return "$x $x"; } say double(21); # 42 say double("Hello"); # Hello Hello
Perl 6 | Cool Perl 6 | #89 |
Type constraints in signature used to select sub:
multi sub double(Num $x) { return 2 * $x; } multi sub double(Str $x) { return "$x $x"; } say double(21); # 42 say double("Hello"); # Hello Hello
Copyright © 2010 http://www.pmichaud.com/2010/pres/ |