Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a few examples for Nil; jnthn++ for the 'evaporation' example
  • Loading branch information
ab5tract committed Jun 8, 2015
1 parent e792986 commit ec2fc82
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/Type/Nil.pod
Expand Up @@ -9,6 +9,29 @@
Represents an empty list in list context, and an undefined value in item
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)
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'
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)
=head1 Methods
Expand Down

0 comments on commit ec2fc82

Please sign in to comment.