My thoughts:
.HOW returns information concerning the implementation type; .WHAT
returns information concerning the value type.
.HOW and .WHAT stringify to something resembling the declarations that
would be used to create them.

Also bear in mind that Perl 6 uses prototype-based object orientation,
except where it doesn't.  As such, when I say that "$x is a Foo"
below, what I mean is that "$x is an object with Foo as its
implementation type".

Jonathan Worthington wrote:
> Hi,
>
>  I'm looking for answers/clarification on what (if taken as individual
> programs) $x is in each case.
>
>  my Int $x;         # $x is Int protoobject
>  say $x;              # Int
>  say $x.WHAT; # Int

.WHAT is an Int; stringifies to "Int".

>  class Foo { }
>  my Foo $x;   # $x is Foo protoobject
>  say $x;          # Foo
>  say $x.WHAT; # Foo
>  # This means we can only assign to $x something that isa Foo?

.WHAT is a Foo; stringifies to "Foo".

>  role Bar { }
>  my Bar $x;   # $x is ???
>  say $x;          # ???
>  say $x.WHAT; # ???
>  # This means we can only assign to $x something that does Bar?

This one's tricky: roles cannot be instantiated, so .WHAT cannot be a
Bar.  My gut reaction is that it's an anonymous class that does Bar
and stringifies to "Bar".  As long as you don't have both a role and a
class named "Bar", this should not be a problem, since the value type
isn't concerned with the implementation.  If it is possible to have
both a role and a class with the same name, you might be able to look
at .WHAT.HOW (or .^WHAT) to figure out with which you're dealing.
That is, the implementation type of the value type ought to provide
more elaborate detail as to the nature of the value type.

>  subset EvenInt of Int where { $_ % 2  == 0 };
>  my EvenInt $x;  # $x is ???
>  say $x;              # ???
>  say $x.WHAT;  # Failure?
>  # This means we can only assign to $x something that matches the constraint

my guess: .WHAT is an EvenInt that stringifies to "EvenInt".  If you
want to know about the structure of EvenInt (e.g., which class is it
based on, and which subset restrictions have been applied to it), you
would refer to .WHAT.HOW.

>  class Dog { }
>  class Cat { }
>  my Dog|Cat $x;  # $x is ???
>  say $x;               # ???
>  say $x.WHAT;  # Failure?
>  # This means we can only assign to $x something that isa Dog or isa Cat

my guess: .WHAT is a Junction that stringifies to "Dog|Cat".  To
access the details as to which classes are in the junction and how
they are joined, refer to appropriate methods (I believe that Junction
includes a method that returns a Set of its members) or maybe to
.WHAT.HOW.

As well:

  class Dog { }
  role Pet { }
  my Pet Dog $x;
  say $x;
  say $x.WHAT;

My guess is that .WHAT would be a (dis)Junction of a Dog and an
anonymous class; the anonymous class does Pet and stringifies to
"Pet", while the Junction stringifies to "Pet Dog".

-- 
Jonathan "Dataweaver" Lang

Reply via email to