develooper Front page | perl.perl6.language | Postings from August 2006

return Types: what are the enforcement details?

Thread Next
Mark Stosberg
August 29, 2006 16:53
return Types: what are the enforcement details?
Message ID:
I'm interested in helping to write some tests for "return types", but
I'd like some clarifications about them first. Are they just
"declarations" that help Perl optimize stuff, or they actually contracts?

As this little script shows, both "inner" and "of" are valid syntax now
with pugs, but neither is considered an error to throw an error when the
different type is actually returned.

I'd like see it documented in exactly what cases errors should be thrown

For reference, return are described here:


sub foo of Array {
    my %h = ( a => 1 );
    return %h;
sub zoo returns Array {
    my %h = ( a => 1 );
    return %h;

# Hashes are happily returned, despite the Array return types.
my %b = foo(); say %b.perl;
my %c = foo(); say %c.perl;

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About