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. For example, it makes more sense (than comparing Weight and Distance) to compare a Manager with an Employee since that can tell you if they are the same Person. It depends on what kind of equality test you are looking to do, at what level of abstraction. -- Darren Duncan

Reply via email to