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

return Types: what are the enforcement details?

Thread Next
From:
Mark Stosberg
Date:
August 29, 2006 16:53
Subject:
return Types: what are the enforcement details?
Message ID:
ed2k1l$sh1$1@sea.gmane.org
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
here.

For reference, return are described here:
http://feather.perl6.nl/syn/S06.html#Return_types

demo:

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About