Daniel Ruoso daniel-at-ruoso.com |Perl 6| wrote:
Very interesting reading... :)It actually made me think that it would be possible to implement it as a pragma. class A { has $.a }; class B { has $.b }; sub foo { A $a } { ... } [sic, should be () around parameters] { foo(B.new()); # FAIL use typematch 'like'; foo(B.new()); # OK use typematch 'does';foo(B.new()); # FAIL }
The problem with doing F-bounds instead of subtype as a normal match is that it does behave differently. It is =not= substitutable for the original type. Unless you are also going to type the variable using a generic type parameter, the code just won't work with it properly. It is up to foo in your example to be written to support higher-order polymorphism on $a. It is not up to the caller to say "take this anyway", unless it is more like the int/float/double case in which case you generate a wrapper to pass. I think there should be syntax to do that explicitly: I've been using the keyword 'shoehorn' for a not-quite-isa cast that adds error checking. My current expositions are to show how casting is never needed, and I carefully avoided even showing one in the example code.
--John
