Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Made example code more compact
  • Loading branch information
Paul Cochrane committed Jun 8, 2015
1 parent 73c23ee commit 8119091
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/Type/Nil.pod
Expand Up @@ -12,26 +12,26 @@ context.
C<Nil>, when assigned, evaporates into the type object of the type of the
container you assigned it into.
my Int $x = 42;
$x = Nil;
$x.say; # (Int)
my Int $x = 42;
$x = Nil;
$x.say; #-> (Int)
It is for this reason that assigning an untyped container as C<Nil> will result
in an C<(Any)> object.
my $x = Nil;
$x.say; # (Any)
my Int $y = $x; # error: Type check failed in assignment to '$y'; expected 'Int' but got 'Any'
my $x = Nil;
$x.say; #-> (Any)
my Int $y = $x; # error: Type check failed in assignment to '$y'; expected 'Int' but got 'Any'
This is because an untyped container is C<Any> until proven otherwise, and
the C<Nil> evaporates.
If you are looking for a variable which transforms objects into type objects
when said variable appears on the RHS, you can type the container as C<Nil>.
my Nil $x;
my Str $s = $x;
$s.say; # (Str)
my Nil $x;
my Str $s = $x;
$s.say; #-> (Str)
=head1 Methods
Expand Down

0 comments on commit 8119091

Please sign in to comment.