Skip to content

Commit ef3187a

Browse files
Closes #2321 (#2325)
* Closes #2321 * Correction of indefinite/definite typo in earlier commit
1 parent a84e802 commit ef3187a

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

doc/Type/Signature.pod6

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ the value part of the L<colon-pair|/type/Pair>.
228228
X<|type constraint,:D>
229229
X<|type constraint,:U>
230230
X<|type constraint,:_>
231-
=head3 Constraining defined and undefined values
231+
232+
=head3 Constraining argument definiteness
232233
233234
Normally, a type constraint only checks whether the value of the parameter is of
234235
the correct type. Crucially, both I<object instances> and I<type objects> will
@@ -259,7 +260,7 @@ and type objects (C<Int>). Consider the following code:
259260
Here we really only want to deal with string instances, not type objects. To do
260261
this, we can use the C<:D> type constraint. This constraint checks that the
261262
value passed is an I<object instance>, in a similar fashion to calling its
262-
L<DEFINITE|/language/mop#DEFINITE> method.
263+
L<DEFINITE|/language/mop#DEFINITE> (meta)method.
263264
264265
To warm up, let's apply C<:D> to the right-hand side of our humble C<Int> example:
265266
@@ -387,6 +388,34 @@ In 6.d language, the default default is the type object without the smiley const
387388
use v6.d.PREVIEW;
388389
my Int:D $x .= new: 42; # OUTPUT: «42␤»
389390
391+
A closing remark on terminology: this section is about the use of the type
392+
smileys C<:D> and C<:U> to constrain the definiteness of arguments.
393+
Occasionally I<definedness> is used as a synonym for I<definiteness>; this may
394+
be confusing, since the terms have subtly different meanings.
395+
396+
As explained above, I<definiteness> is concerned with the distinction between
397+
type objects and object instances. A type object is always indefinite, while an
398+
object instance is always definite. Whether or not an object is a type
399+
object/indefinite or an object instance/definite can be verified using the
400+
L<DEFINITE|/language/mop#DEFINITE> (meta)method.
401+
402+
I<Definiteness> should be distinghuished from I<definedness>, which is concerned
403+
with the difference between defined and undefined objects. Whether an object is
404+
defined or undefined can be verified using the C<.defined>-method, which is
405+
implemented in class L<Mu|/type/Mu>. By default a type object is considered
406+
undefined, while an object instance is considered defined; that is: C<.defined>
407+
returns C<False> on a type object, and C<True> otherwise. But this default
408+
behaviour may be overridden by subclasses. An example of a subclass that
409+
overrides the default C<.defined> behaviour is L<Failure|type/Failure>,
410+
so that even an instantiated C<Failure> acts as an undefined value:
411+
412+
my $a = Failure; # Initialize with type object
413+
my $b = Failure.new("foo"); # Initialize with object instance
414+
say $a.DEFINITE; # Output: «False␤» : indefinite type object
415+
say $b.DEFINITE; # Output: «True␤» : definite object instance
416+
say $a.defined; # Output: «False␤» : default response
417+
say $b.defined; # Output: «False␤» : .defined override
418+
390419
=head3 Constraining signatures of C<Callable>s
391420
392421
The signature of a L<Callable> parameter can be constrained by

0 commit comments

Comments
 (0)