On 2009-Oct-14, at 2:00 pm, Jon Lang wrote:
David Green wrote:
On the other hand, $dogwood.Dog::bark cannot be simplified by
leaving out the "Dog::" because then it would be ambiguous.
On the gripping hand, if we have a function "train(Dog $d)", then we
can safely assume that within the lexical scope of train, $d is
supposed to be treated as a Dog. So within that lexical scope, it
should be safe to leave off the "Dog::".
Yes; and then my question from last time is whether the sig (Dog $d)
"soft-casts" the arg such that the non-doggy bits of $d still remain,
e.g. if inside train() we call a function chop(Tree $t), chop() will
unambiguously see the Tree-half of the original Dogwood object. Or
will it be "hard-cast" such that the non-doggy bits are simply lost?
(And if so, does an ordinary cast Foo($d) do the same thing, or is one
"hard" and one "soft", etc.?)
The soft way -- being able to cast $dogwood as a Dog and treat it
unambiguously so, then to do the same thing treating it as a Tree
object -- is the most flexible. Split-personality Dogs may be rare,
but I can imagine wanting to call common utility roles (e.g. Logging)
from any point down a calling chain.
However, I expect that "my Dog $d = $dogwood" would strip out
everything else, on the grounds that you explicitly requested a pure
Dog object. Otherwise you could have said "my $d = Dog($dogwood)" or
maybe "my $dogwood.^WHAT $d = $dogwood" instead.
-David