Metamodel::DefiniteHOW Reference
Metaobject for type definiteness
What it is #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
method new_type #
method new_type(:$base_type!, :$definite!)
Creates a new definite type given a base type and definiteness. $definite should either be 1 for :D types or 0 for :U types.
method name #
method name($definite_type)
Returns the name of a definite type.
method shortname #
method shortname($definite_type)
Returns the shortname of a definite type.
method base_type #
method base_type($definite_type)
Returns the base type for a definite type:
method definite #
method definite($definite_type)
Returns 1 if the definite type given is a :D type or 0 if it is a :U type.
method nominalize #
method nominalize($obj)
Produces a nominal type object for a definite type. This is its base type, which may also get nominalized if it has the nominalizable archetype.
method find_method #
method find_method($definite_type, $name)
Looks up a method on the base type of a definite type.
method type_check #
method type_check($definite_type, $checkee)
Performs a type-check of a definite type against $checkee. This will check if $checkee is of its base type, returning True if they match or False otherwise. This metamethod can get called when a definite type is on the left-hand side of a smartmatch, for instance.
method accepts_type #
method accepts_type($definite_type, $checkee)
Performs a type-check of $checkee against a definite type. This will check if $checkee is of its base type and matches its definiteness, returning True if they match or False otherwise. This metamethod can get called when the definite type is on the right-hand side of a smartmatch, for instance.
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
3 no-output · 3 ok
class Metamodel::DefiniteHOW
does Metamodel::Documenting
{ }Not executed: the documentation states no expected output for this example.
say Any:D.^name; # OUTPUT: «Any:D» say Any:U.^name; # OUTPUT: «Any:U» say Any:_.^name; # OUTPUT: «Any»
Any:D
Any:U
Any
Documentation, Rakudo and Raku++ all agree.
say Any ~~ Any:D; # OUTPUT: «False» say Any ~~ Any:U; # OUTPUT: «True» say Any ~~ Any:_; # OUTPUT: «True» say Any.new ~~ Any:D; # OUTPUT: «True» say Any.new ~~ Any:U; # OUTPUT: «False» say Any.new ~~ Any:_; # OUTPUT: «True»
False
True
True
True
False
True
Documentation, Rakudo and Raku++ all agree.
my Any constant Definite = Any:D;
Not executed: the documentation states no expected output for this example.
my Any constant Definite = Metamodel::DefiniteHOW.new_type: base_type => Any, definite => 1;
Not executed: the documentation states no expected output for this example.
say Any:D.^base_type.^name; # OUTPUT: «Any»
Any
Documentation, Rakudo and Raku++ all agree.