Types, classes & roles

Definedness & type objects

Full

Every type has an undefined "type object"; .defined tells values and types apart.

Definedness is distinct from truth. Every type has a type object — an undefined instance of the type (Int, Any, …) — and .defined distinguishes it from a real value. This is what with/without and optional parameters key on.

Values are defined, type objects are not #

my $x;
say $x.defined;
say 0.defined;
say Any.defined;
Output
False
True
False

An uninitialised $x holds Any (undefined); 0 is a defined value even though it is false; a bare type name is the undefined type object.

Nil and type objects #

say Nil.defined;
say (Int).defined;
say 42.defined;
Output
False
False
True

Int (the type object) is undefined; 42 (an instance) is defined.

Notes #