Hi,
class Foo {...}
Foo.new.isa(Foo); # true
Foo.isa(Foo); # true (see [1])
Foo.does(Class); # true
sub blarb (Foo $foo, $arg) {
...; # Do something with instance $foo
}
blarb Foo.new(...), ...;
# No problem
blarb Foo, ...;
# Problem, as &blarb expects an *instance* of Foo,
# not the class Foo.
How do I have to annotate the type specification in the
declaration of the subroutine to not include the class Foo, but
only allow instances of Foo?
Or is the default way to check the types of arguments
something like the following, in which case my first question
doesn't arise?
if $param ~~ $expected_type and not $param ~~ Class {
# ok
} else {
die "Type error: ...";
}
(But this feels special-casey...)
(And, just curious -- how can I override the default checking
routine?)
--Ingo
[1] http://www.nntp.perl.org/group/perl.perl6.language/22220
--
Linux, the choice of a GNU | Row, row, row your bits, gently down the
generation on a dual AMD | stream...
Athlon! |
Thread Next