Skip to content

Commit 644d726

Browse files
committed
Explain type smilies
1 parent ae631ec commit 644d726

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

doc/Language/faq.pod

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ In this example, the result of the comparison (which is a
2121
L<Junction|/type/Junction>), is
2222
converted to Bool before being printed.
2323
24+
=head2 What are those C<:D> and C<:U> things in signatures?
25+
26+
In Perl 6, classes and other types are objects, and pass type checks
27+
of their own type.
28+
29+
For example if you declare a variable
30+
31+
my Int $x = 42;
32+
33+
then not only can you assign integers (that is, instances of class Int) to it,
34+
but the C<Int> type object itself:
35+
36+
$x = Int
37+
38+
If you want to exclude type objects, you can append the C<:D> type smiley,
39+
which stands for "definite":
40+
41+
my Int:D $x = 42;
42+
$x = Int; # dies with:
43+
# Type check failed in assignment to $x;
44+
# expected Int:D but got Int
45+
46+
Likewise C<:U> constrains to undefined values, that is, type objects.
47+
48+
To explicitly allow either type objects or instances, you can use C<:_>.
2449
2550
=head2 How can I extract the values from a Junction?
2651

0 commit comments

Comments
 (0)