User loginNavigation |
beyond multi-methodsPredicate Dispatching: A Unified Theory of Dispatch by Michael Ernst, Craig Kaplan, and Craig Chambers, ECOOP'98 [gud-ecoop98.ps.gz] introduced the concept of predicate dispatching which ... generalizes previous method dispatch mechanisms by permitting arbitrary predicates to control method applicability and by using logical implication between predicates as the overriding relationship. The method selected to handle a message send can depend not just on the classes of the arguments, as in ordinary object-oriented dispatch, but also on the classes of subcomponents, on an argument's state, and on relationships between objects. This simple mechanism subsumes and extends object-oriented single and multiple dispatch, ML-style pattern matching, predicate classes, and classifiers, which can all be regarded as syntactic sugar for predicate dispatching. A simple example that implements zip: type List; class Cons subtypes List { head:Any, tail:List}; class Nil subtypes List; signature Zip(List, List): List; method Zip(lst1, lst2) when lst1@Cons and lst2@Cons { return Cons(Pair(lst1.head, lst2.head), Zip(lst1.tail, lst2.tail)); } method Zip(lst1, lst2) when lst1@Nil or lst2@Nil { return Nil; } This is better than multi-methods because ... a lexicographic ordering for multimethods [Ste90] is error-prone and unnatural, and programmers are not warned of potential ambiguities. In a traditional (singly- or multiply-dispatched) object-oriented language without the ability to order cases, either the base case of Zip must be written as the default case for all pairs of List objects (unnaturally, and unsafely in the face of future additions of new subclasses of List), or three separate but identical base methods must be written: one for Nil×Any, one for Any×Nil, and a third for Nil×Nil to resolve the ambiguity between the first two. In our experience with object-oriented languages (using a pointwise, not lexicographic, ordering), these triplicate base methods for binary messages occur frequently. By el-vadimo at 2008-09-20 15:49 | LtU Forum | previous forum topic | next forum topic | other blogs | 5593 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago