Ph. Marek philipp.marek-at-bmlv.gv.at |Perl 6| wrote:
I think that's a can of work, and I'd be +1 on TSa:
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.
Since typed variables will still stringify and numify just fine:
my Num $x = 123;
say $x ~~ " bottles of beer";
the dynamic type is indeed Num. It just has the capability of being
coerced to a string, which is called implicitly in various situations.
"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.
"10".WHAT returns the undefined prototype of Str. It also stringifies to
the short name of the class.
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.
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.
--John