[comp.lang.eiffel] Eiffel type system

arapis@cui.unige.ch (Constantin Arapis) (02/07/91)

        QUESTION CONCERNING THE TYPE SYSTEM OF EIFFEL
        ---------------------------------------------


I don't know whether the following issue on the type system of Eiffel
has ever been discussed in this group.

It is obvious that the type system of Eiffel is essentially the type
system published in [Cardelli84]. However, between the two type
systems there is a difference concerning the redefinition of operations.
In [Cardelli84] the type of the argument of the redefined routine
must be a supertype of the original type.
In Eiffel the oppposite is required, that is the type of the argument
of the redefined routine must be a subtype of the original type.

The program below ilustrates this situation in Eiffel: the routine op
of class C1 has been redefined in class C2. The type of the argument
is T1 in class C1 while in C2 the type of the argument is T2 (a subtype
of T1).

The rule adopted by Eiffel may lead to correct typed programs (no compile
errors) which whenever executed produce run-time errors (version 2.1
of Eiffel).

Such errors could be avoided if Eiffel had adopted exactly
the rules of the type system described in [Cardelli84].

My question is why Eiffel has adopted this rule?
Was it an error design?
If it is not a design error which considerations led to that choice?

 ---------------------------------------------------------------

        class T1
                export print1
                feature
                        io: STD_FILES;

                        Create is do
                                io.Create;
                        end;

                        print1 is do
                                io.output.putstring("object T1\n");
                        end;
        end;

        class T2
                export print1, print2
                inherit T1
                feature
                        Create is do
                                io.Create;
                        end;
 
                        print2 is do
                                io.output.putstring("object T2\n");
                        end;
        end;
 
        class C1
                export op
                feature
                        op(arg: T1) is do
                                arg.print1;
                        end;
        end;
 
        class C2
                export op
                inherit C1 redefine op
                feature
                        op(arg: T2) is do
                                arg.print1;
                                arg.print2;
                        end;
        end;
 
        class MAIN
                feature
                        objC1: C1;
                        objC2: C2;
                        objT1: T1;
 
                        Create is do
                                objC2.Create;
                                objC1 := objC2;
                                objT1.Create;
                                objC1.op(objT1);   -- !!! RUN-TIME ERROR
                        end;
        end;
 
   -------------------------------------------------------------

[Cardelli84] Cardelli 1984
A Semantics of Multiple Inheritance.
In Semantics of Data Types. Lecture Notes of Computer Science, Vol. 173,
edited by G.Kahn, D. MacQueen, and G. Plotkin
Springer-Verlag.
 
 
Constantin Arapis
Centre Universitaire Informatique
University of Geneva
e-mail: arapis@cuisun.unige.ch