[PRL] IOP and disjoint unions

David Herman dherman at ccs.neu.edu
Thu Apr 28 20:57:18 EDT 2005


> LambdaTerm = (LambdaTerm x LambdaTerm)        // Application
>            + String
>            + double
>            + (String x LambdaTerm)            // Abstraction
>            + (LambdaTerm x LambdaTerm)        // Selection
>
> Is this really going to save you from writing a lot of code?

Well, you can use inheritance:

     abstract class BinaryTerm implements LambdaTerm {
         public LambdaTerm leftTerm() { ... }
         public LambdaTerm rightTerm() { ... }
     }

     class ApplicationTerm extends BinaryTerm { ... }
     class SelectionTerm extends BinaryTerm { ... }

But at least in Java, the only way the two similar summands can share 
any code is to use classes instead of interfaces. In a language where 
interfaces can have default implementations (such as Scala's traits) 
you could probably still do this with interfaces.

Dave




More information about the PRL mailing list