Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!dino!bambam.cs.iastate.edu!leavens From: leavens@cs.iastate.edu (Gary Leavens) Newsgroups: comp.object Subject: Re: Do we really need types in OOPL's? Summary: Yes we do Keywords: types, classes, subtypes Message-ID: Date: 28 Sep 90 14:14:49 GMT Sender: usenet@dino.cs.iastate.edu Distribution: comp Lines: 47 In comp.object you write: >Why does Eiffel try to be a typed language? Shouldn't dynamic binding >allow for any type to be assigned to anytype? It might be a nice feature >to restrict assignments (dynamic binding) in some cases but in others >I don't think so. >In an ideally object-oriented language shouldn't you be able to assign >a class of any type to another class of any type as long as the >client that is assigning them knows their interface and does not >abuse it? You really answer your own question. A programming language's type system can help ensure that, you "know the interface" of each object and do not abuse it. What does that mean? Each object supports a protocol (messages with certain arities). So think of the type of a variable (or expression) as the minimum protocol that the objects that the variable can denote at run-time is guaranteed to support. This naturally leads to a (weak) notion of subtype/supertype relationships. That is, if S is a weak subtype of T, then objects of type S respond to all the messages to which objects of type T respond. Now let the type system enforce the invariant that each variable (and expression) of type T can only denote objects of a weak subtype of T. Furthermore, that you are only allowed to send a message to an expression of type T provided that it is in the protocol of T. It follows that you will never get a "message not understood" error at run-time. (See why?) Type systems like this have been known since Cardelli's work in 1984, and have been used in Trellis/Owl. This also seems to be the intention of the Eiffel type system. However, Eiffel goes further, and uses a stronger subtype relationship that helps one reason about programs. See Meyer's book, or my article "Reasoning about Object-Oriented Programs that use Subtypes" (with William Weihl) that will appear in ECOOP/OOPSLA '90. Gary Leavens -- 229 Atanasoff Hall, Department of Computer Science Iowa State University, Ames, Iowa 50011-1040, USA phone: (515) 294-1580