Re: looking for a predicate hierarchy



aloha.kakuikanu wrote:
Laurent Deniau wrote:

I am looking for a library (of an OO language) which uses a hierarchy of
classes for predicate (type) dispatch in the context of multimethod. Ce
concept is already well know and developed in the literature, but
languages which support multimethods and metaclasses are not so common.
Therefore, I have some difficulty to find such 'standard' use of class
as predicates. The papers usually use hierarchies inspired from specific
taxonomy (e.g. animals) which are not general enough to be useful.

For the moment in my lib I have (<- means 'inherits from'):

Predicate (root class)
<- Nil
<- TrueFalse
<- True
<- False
<- Ordered
<- Lesser
<- Equal
<- Greater

But there is a lot of other possible predicates (not all useful):

Next, Previous
Forward, Backward
Open, Close
Front, Rear
Bottom, Top
Before, After
Up, Down
Even, Odd
Left, Right
North, South, Est, West

etc...

and selecting the predicates general enough (aliases and user defined
predicates are always possible as extension) is somehow a problem of
experience. BTW, the hierarchy stigmatize the possible logical
combinations of the predicates (not, and, or) and strengthens the
importance of its design (e.g. TrueFalse != Boolean).

Has somebody already seen such hierarchy? Links and references would be
really appreciated. Thanks.


What do you mean by "predicate"? Is it logical concept?

I am talking about class/type predicate in the context of mutlimethod dispatch. For example, a binary method with True as its type specialisation for its second formal argument answer positively if the second argument on the caller side *is of class* True (or a subclass of True).

class predicate dispatch is a subset of predicate dispatch which does not include dispatch on boolean expression.

Then we can
talk about relations in the database theory sence, both finite and
infinite. Relations do form a lattice, so you work out tthis idea into
extracting a "hierarchy" out of the lattice. But is this really what
you want to do?

Maybe ;-)

In fact multimethod implement natively the logical AND while inheritance implement natively the logical OR between types/classes. State exclusion is represented by different branches in the hierarchy.

Considering the first case (TrueFalse):

- TrueFalse is the indeterminate/uncertain state (also called the third state in tribool and noted '?')
- True and False are (exclusive) specialization of TrueFalse by inheritance.
- Specialisation can be used to perform state complement (logical NOT) because most specific specialisation are selected first.

With these observations, it is easy to build logical tables with the 3 states by writing 4 specialisations (instead of 9). For example, AND is (sample of my code):

/*

AND | F | T | ?
----+---+---+---
F | F | F | F
T | F | T | ?
? | F | ? | ?

*/

defmethod(OBJ, And, (False,TrueFalse))
retmethod(False);
endmethod

defmethod(OBJ, And, (TrueFalse,False))
retmethod(False);
endmethod

defmethod(OBJ, And, (TrueFalse,TrueFalse))
retmethod(TrueFalse);
endmethod

defmethod(OBJ, And, (True,True))
retmethod(True);
endmethod

Note that because of inheritance and specialization, this hierarchy is still valid if you restrict the allowed states only to True and False.

The same can be done for Ordered, which could also be understood as Unordered depending on the existing specialisations. The advantage is that the hierarchy above can represent the relation:

no order: specialisation on Ordered (as 'Unordered') only
total order: specialisation on Lesser, Equal and Greater only
partial order: idem total order plus specialisation on Ordered

So the same hierarchy can be applied to many cases where the defined multimethods (the hierarchy is fixed) caracterise the allowed relation.

a+, ld.

.



Relevant Pages

  • Re: Googles Go language and "goroutines"
    ... the subject and objects are objects, but the predicate is a predicate ... be subtypes. ... interface Furniture extends Stuff ... yesterday's hierarchy is out of date. ...
    (comp.lang.tcl)
  • Re: looking for a predicate hierarchy
    ... I am talking about class/type predicate in the context of mutlimethod ... But since I am working on dynamic dispatch with dynamic ... What does "dispatch on Boolean expression mean?" ... procedure Vote (X: in out Adult); ...
    (comp.object)
  • Re: looking for a predicate hierarchy
    ... I am talking about class/type predicate in the context of mutlimethod ... not include dispatch on boolean expression. ... Any constraint imposed on the values ... means that this vote specialization will be called if the type of its ...
    (comp.object)
  • Re: What should the semantics of hierarchical modules be?
    ... > Brian Hulley wrote: ... >> since the new predicate, added by someone else or the same person ... > - generate a warning whenever a definition hides a definition ... > higher up in your module hierarchy ...
    (comp.lang.prolog)

Loading