File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,31 @@ In this example, the result of the comparison (which is a
21
21
L < Junction|/type/Junction > ), is
22
22
converted to Bool before being printed.
23
23
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 < :_ > .
24
49
25
50
= head2 How can I extract the values from a Junction?
26
51
You can’t perform that action at this time.
0 commit comments