Monday, September 04, 2006

Modular Predicate Dispatch

Tom's post on interfaces reminded me of a paper and software I looked at in 2004 that implemented multiple dispatch using predicate inference in order to execute the correct method on a class. It was interesting at the time as it seems like a natural evolution of propositional logic technologies including things like the Semantic Web. Not to mention an implementation of the Visitor pattern that was quite neat.

A new paper released early this year, "Modularly Typesafe Interface Dispatch in JPred", in which they talk about the way they've successfully added support for predicate dispatch on interfaces. This is much better than most previous approaches, as far as I can tell. It's interesting that the type inferencing in their compiler was able to help debug the compiler itself.

They make reference to the Multijava project which adds open classes and symmetric multiple dispatch - but is limited to using classes and not interfaces like JPred originally was. Open classes are a way of getting some of the benefits that the Visitor pattern without modifying as much code. More details are in this paper.

The code looks like:
class C {
void m(Object o) {
System.out.println("got a C and an Object");
}
}
class D extends C {
void m(final Object o) {
System.out.println("got a D and an Object");
super.m(o);
this.resend(o);
}
}


The 2006 paper also references, "featherweight Java", which seems to have opened up a whole range of academic possibilities.

No comments: