On Tue, May 06, 2008 at 07:01:29PM -0700, Jon Lang wrote: : 1. Apparently, my presumption that $x.WHAT was for retrieving the : value type was wrong; from the above, it's sounding like it is : supposed to retrieve the implementation type.
I don't know what you mean by those terms. .WHAT gives you an value of undef that happens to be typed the same as the object in $x, presuming your metaobject believes in types. .HOW gives you the metaobject that manages everything else for this object. It might or might not believe in classes or types. : Is this correct? If : so, for what purpose does $x.WHAT exist that you can't do just as well : with $x itself? You can do type reasoning with the WHAT type just as you can with a real value of the same type. Int is a prototypical integer from the standpoint of the type system, without actually having to *be* any particular integer. In contrast, the .HOW object for Int is very much *not* an Int. Perl doesn't know or care what the type of the .HOW object is, as long as it behaves like a metaclass in a duck-typed sort of way. It's probably a mistake to try to use the type of the .HOW object in any kind of type-inferential way. : If it's for the stringification of the container's : name, couldn't that be accomplished just as easily by means of a : $x.HOW method, such as $x.^name? No, that's not what it's for at all. It's only convenient that it generally stringifies to something that looks like a package name, assuming it's not an anonymous type. But the primary purpose is to provide a closed system of types that is orthogonal to whether the object is defined or not. In Haskell terms, they're all Maybe types, only with a little more ability to carry error information about *why* they're undefined, if they're undefined. : 2. How _do_ you retrieve the value type of $x? Do you mean the variable, or its contents? The contents returns its object type via $x.WHAT, which for an Int is always Int, regardless of any extra constraints imposed by the container. : That is, how can the : program look at $x and ask for the constraints that are placed on it? Placed by the variable, or by the type of the contents? The constraints on the value are solely the concern of whatever kind of object it is. If you mean the constraints of the container, then VAR($x).WHAT will be, say, Scalar of Int where 0..*, and VAR($x).of probably can tell you that it wants something that conforms to Int. I'm not sure if the "of" type should include any constraints, or just return the base type. Probably a .where method would return extra constraints, if any. : I don't see $x.HOW being useful for this, since HOW is essentially : there to let you look at the inner workings of the container; and none : of the other introspection metamethods in S12 come close to addressing : this question. $x.HOW is not the inner workings of the container, but of the value. You'd have to say VAR($x).HOW to get the inner workings of the container. Scalar containers always delegate to their contents. In contrast, @x.HOW would be equivalent to VAR(@x).HOW, because composite objects used as scalars assume you're talking about the container. Larry