On Thu, Apr 24, 2008 at 09:15:15PM +0200, TSa wrote:
> 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
You are confusing the container with the object. .WHAT and .HOW are
both dynamically typed, and $x.WHAT returns Str, because objects do
not carry subtypes. The container enforces the ThreeChars constraint,
but does not require a ThreeChars object.
And .HOW doesn't return Str, it returns a metaobject of some sort, which
might be the same as ^Str in a class-based system, but needn't.
In your drive to separate types from values, please note that Perl 6
considers all values to be subsets. 'xxx' is just a Str that is
constrained to be equal to three x's. So please don't also try to
make subsets into real types, if you want to keep your types separate...
Larry
> 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