Darren Duncan wrote:
> Larry Wall wrote:
>>
>> Or going the other direction, perhaps we're missing a primitive that
>> can produce a data structure with the type information stripped, and
>> then eqv might be able to determine structural equivalence between
>> two canonicalized values.
>
> Often you still want to know the declared type, though, because while
> sometimes we want things to be equivalent if they are structurally
> equivalent, other times we don't.  A declared type implies a particular
> intended interpretation of a value.  For example, we could have two classes
> named Weight and Distance, both of which have a single Num-typed attribute
> named $v.  A structural comparison of a Weight.new(3) and a Distance.new(3)
> may consider them equal, but logically we would want those two to not
> compare equal, because no weight is a distance or vice-versa, so every
> Weight should compare as not equal to every Distance. Ignoring the declared
> type only really makes sense when the two values are subtypes of a common
> parent type.  It only makes sense for objects of two classes to be declared
> equal if you can say that a value of a type "is a" value of the other type.

Right.  Still, there are times when duck-typing, flawed as it is,
might be exactly what is needed to resolve the problem at hand.  I
forget who or in what context, but I vaguely recall someone posting an
article here that proposed the use of £ in signatures as a modifier to
mean "is like a" (i.e., accept anything that matches the given role's
set of methods; duck-typing) rather than "is a" or "does" (which,
respectively, check for inheritance or composition).  (Could the
original poster please repost the link here for reference purposes?)

To me, this seems like a rather perlish solution: allow perl to do
duck-typing, but not as the default means of type comparison; require
some additional syntax to enable it.  So looking for "Weight" only
succeeds when the test subject inherits or composes Weight; but
looking for "£ Weight" succeeds for anything that acts like a Weight.

-- 
Jonathan "Dataweaver" Lang

Reply via email to