[PRL] IOP and disjoint unions
Richard Cobbe
cobbe at ccs.neu.edu
Thu Apr 28 16:17:29 EDT 2005
On Thu, Apr 28, 2005 at 03:45:45PM -0400, Carl Eastlund wrote:
> On 4/28/05, Dave Herman <dherman at ccs.neu.edu> wrote:
> > When you're writing OO code in an interface-oriented way, how do you
> > encode disjoint unions? The typical way to do it in class-based
> > languages is to encode the variants as subclasses of a base class.
> >
> > But in IOP this would entail a separate interface for each variant
> > (blech). Worse, variants of disjoint unions in ML-like languages are
> > distinguished with dynamic tags, not static types; this would suggest a
> > dynamic interface check, which contradicts the intuition of interfaces
> > as being static.
>
> What's wrong with a separate interface for each variant? In ML, you
> have a separate type for each variant, and interfaces have a lot in
> common with types. Further, what's wrong with using instanceof checks
> in place of ML's pattern matching or Scheme's constructor predicates?
> And who said anything about interfaces being purely static entities?
First, do you really have a separate type for each variant in ML?
Second, at least in our current thinking about Honu, interfaces/types
are not purely static entities any more than they are in Java.
The cast expression takes an interface name, rather than a class name,
and succeeds only if the object is an instance of a class that
implements the specified interface.
> interface AbsSyn {
>
> // Predicates report whether expression has the queried form.
> Bool isAbs();
> Bool isVar();
> Bool isApp();
>
> // Selectors produce data from within the expression,
> // or raise InvalidSelector if expression does not have expected form.
> String varName();
> String absVar();
> AbsSyn absBody();
> AbsSyn appProc();
> AbsSyn appArg();
> }
That's essentially what Matthias envisions for Honu, in so far as I
understand it. I haven't heard his justification for a single type as
opposed to four types. (The language can express both, of course.)
Richard
More information about the PRL
mailing list