TSa (Thomas Sandlaß) wrote:
Is there also an answer to the odering versus metric question?
Why was the former rejected and the latter choosen?
MMD is really just a partitioning of the discrete N-dimensional search space
formed by the class hierarchies of the N parameters of a multimethod/multisub.
A linear summation (or other geometric) metric ensures that the search space
is completely partitioned by whatever variants are defined for a given multi.
A "pure ordering" dispatch scheme generally leaves large regions of the search
space unclaimed by any variant, necessitating the definition of numerous extra
variants solely for the purpose of disambiguation.
This larger number of ambiguous (and therefore undispatchable) argument lists
reduces the utility and forward compatibility of "pure ordering" multiple
dispatch, by forcing the developer to specify a much larger number of
variants, most of which will then have to delegate to a single variant (which
is typically the one a linear metric would have chosen anyway).
There's a strong parallel with allowing shift-reduce ambiguities in LR
parsers. You *could* make the developer explicitly cover all the possible
interpretations of a given sequence of symbols, but only at the cost of
exponentially increasing the number of grammar rules being required.
Similarly, since the number of potential variants is the Cartesian product of
the total sizes of the class hierarch(y|ies) for each parameter position,
getting adequate coverage of the MMD search space quickly becomes tedious if
most of the search space is (by default) ambiguous, as in "pure ordering"
dispatch schemes.
One very common problem with pure ordering schemes is that subsequent changes
in one or more class hierarchies can cause previously unambiguous cases to
become ambiguous, by extending a zone of ambiguity in the search space. In
contrast, because a metric approach always fully partitions the entire search
space, hierarchy changes may alter where a particular call dispatches to, but
only ever to a "closer", more appropriate variant.
Note too that Perl 6 *will* still support a form of "pure ordered" dispatch--a
left-most-closest-match scheme like that used by CLOS--via "invocant groups":
multi sub Foo(A: B: C:) {...}
multi sub Foo(A: D: C:) {...}
multi sub Foo(F: B: G:) {...}
This, of course, is not "global pure ordering", but rather "left-biased pure
ordering".
To summarize: pure ordering renders more of the MMD search space "ambiguous",
which is potentially safer but much less DWIMish. Metric schemes have far
fewer ambiguities and usually dispatch in an predictable way. Metric schemes
can still provide pure-ordering analyses via static analysis tools or special
warning modes, but pure ordering schemes can't avoid ambiguities or DWIM.
Of course, none of this prevents:
use MMD <pure>;
Damian