Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
some disambiguation
  • Loading branch information
TimToady committed Aug 8, 2011
1 parent 35e20e2 commit 5645947
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions S02-bits.pod
Expand Up @@ -14,7 +14,7 @@ Synopsis 2: Bits and Pieces
Created: 10 Aug 2004

Last Modified: 8 Aug 2011
Version: 237
Version: 238

This document summarizes Apocalypse 2, which covers small-scale
lexical items and typological issues. (These Synopses also contain
Expand Down Expand Up @@ -1569,19 +1569,19 @@ See L<S06/"Wrapping"> for a discussion of soft vs. hard routines.
Explicit types are optional. Perl variables have two associated types:
their "of type" and their "container type". (More generally, any
container has a container type, including subroutines and modules.)
The of type is stored as its C<of> property, while the container
The C<of> type is stored as its C<of> property, while the container
type of the container is just the object type of the container itself.
The word C<returns> is allowed as an alias for C<of>.

The of type specifies what kinds of values may be stored in the
variable. An of type is given as a prefix or with the C<of> keyword:
The C<of> type specifies what kinds of values may be stored in the
variable. An C<of> type is given as a prefix or with the C<of> keyword:

my Dog $spot;
my $spot of Dog;

In either case this sets the C<of> property of the container to C<Dog>.

An of type on an array or hash specifies the type stored by each element:
An of type C<on> an array or hash specifies the type stored by each element:

my Dog @pound; # each element of the array stores a Dog

Expand All @@ -1601,6 +1601,9 @@ To coerce your return value, use a coercion type:

sub get_pet() returns Pet(Animal) {...} # coerce any Animal to Pet

For a container, however, use of a coercion type as the C<of> coerces
upon setting rather than returning the value.

=head2 Container types

The container type specifies how the variable itself is implemented. It is
Expand Down

0 comments on commit 5645947

Please sign in to comment.