HaloO,

John M. Dlugosz wrote:
If the programmer really wants to decrement "10" to "09" she has to cast that to Str: ("10" as Str)--. So we have "10".HOW === Str but "10".WHAT === Num Str.

It's behaving as Num ∪ Str, while the declaration Num Str in juxtaposition means Num ∩ Str.

Hmm? I meant Num ∩ Str. This intersection type is a subtype of
Str and Num without type coercion and it beats both in specificity
when it comes to dispatch.


"10".HOW returns something that does the Metaobject role, which itself can stringify to the name of the Perl 6 class in this case, but the details depend of the object system. In a JavaScript or Self object model, there might not be classes. But what it stringifies to isn't really discussed.

Yes. It returns the instance manager since instance management is the
prime task of a class.


"10".WHAT returns the undefined prototype of Str. It also stringifies to the short name of the class.

I had hoped that WHAT denotes a more specific type than HOW. E.g.

   subset ThreeChars of Str where {$_.elems == 3}

   my ThreeChars $x = 'xxx';

   $x.WHAT;  # ThreeChars
   $x.HOW;   # Str

   $x === 'xxx'; # false because type i.e. the WHAT
                 # has to be the same

It were interesting to know what $x.new returns. If that dispatches
to Str the result is '' which is not a ThreeChars. So how does the
subset declaration make it return e.g. '   '? Looks like one needs
more than a subset declaration to make a proper subtype ;)


Using Str by itself is a listop with no parameters and returns the undefined prototype. So

say "10".WHAT === Str;

prints True. Both refer to the same value: the undefined prototype object of type Str. If the undefined prototype is guaranteed to be singular, then =:= would also show True.

Sounds reasonable. The HOW behind Str might e.g. be PerlStr.


say "10".HOW === Str;

prints False. The left side is a Metaobject, the right a Str mixed in with something that delegates class methods and overrides stringification etc. The things you can call on them are different. They could not be implemented as the same object.

How would Str be implemented then? It is more concrete than a role but
more abstract than a class.


Regards, TSa.
--

"The unavoidable price of reliability is simplicity"
  -- C.A.R. Hoare

Reply via email to