TSa Thomas.Sandlass-at-barco.com |Perl 6| wrote:

The fundamental flaw of metric mmd is that it trades degrees of
specificity. Consider the subtype chain E <: D <: C <: B <: A
where the rule is that having an E it is better handled by a
method dealing with a D than one dealing with an A. The same
is the case for having a D being better handled by a C than an
A method. Now consider a multi with the two signatures :(A,C,C)
and :(D,A,A) and a call with (E,D,D) that goes to :(D,A,A) since
7 < 8. But note that it handles the two Ds as As instead of Cs
as in single dispatch.




OK, why would someone create those forms in the first place? The subtyping relationship could mean either value subset (e.g. integer passed to code that can handle reals) or polymorphic "isa" objects. The implementation should treat the E correctly because of virtual functions on E, even though the code was written for an A. So why write different forms with =related= classes? I would define operators with the same name around unrelated classes, so I can use that operator with things that don't already know what to do.

So why are we focusing on the pathalogical cases? That's like saying we should not support division because you could divide by zero. Rather, what is the common typical use? For the bad stuff, "don't do that" and "do this instead". I think the MMD should work well and be tuned for the areas in which it ought to be used, and the above problem analyzed to see what the programmer was really trying to accomplish.

Maybe for special tuning in hacked-up (as opposed to nicely refactored code) we need something like submethods, that handle the exact case and don't get in the way of other distances. Maybe some of this should be done with generics rather than MMD.

For example, I don't need to define something on a wide variety of number-like types individually, I'll use generic types to specify the minimal properties of the kind of type it applies to, and that the arguments match. So my MMD is between two forms: "anything that is integral in nature" and "anything that is a type of Vehicle", without any analysis concerning whether a Bus is more like a generic Vehicle than a BCD is like an abstract integer concept.

--John

Reply via email to