Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!uunet!mcsun!ukc!pyrltd!tetrauk!rick From: rick@tetrauk.UUCP (Rick Jones) Newsgroups: comp.object Subject: Re: A Hard Problem for Static Type Systems Message-ID: <1147@tetrauk.UUCP> Date: 30 Apr 91 10:53:34 GMT References: <554@eiffel.UUCP> <1991Apr26.203642.17387@leland.Stanford.EDU> <556@eiffel.UUCP> <52166@nigel.ee.udel.edu> Reply-To: rick@tetrauk.UUCP (Rick Jones) Organization: Tetra Ltd., Maidenhead, UK Lines: 70 new@ee.udel.edu (Darren New) writes: > Doesn't look like you've answered the question here. What's the > type of `min'? I feel this does deserve a bit of expansion. To explain the implication of "Current" in Eiffel, it is first necessary to point out that routines in Eiffel can only exist as features of classes. A class is the only form of code module in Eiffel, and everything is written within the boundaries of some class. Thus there is no such thing as "the" min function - many classes may provide a "min" function. A function can only be invoked via a non-void reference to an object of that class. A function such as "min" would in fact be written as a function of say a number class, and would return either the object on which it is called or its argument, whichever is the smaller. I.e. (fragment code of class NUMBER) class NUMBER export min feature min (other: like Current): like Current is do if other < Current then Result := other else Result := Current end end end "Current" is the current object, and "like Current" is the same type as the current object. So in this example "like Current" is the same as NUMBER. In use: num1, num2, num3: NUMBER ; -- ... values assigned to num1 & num2 ... num3 := num1.min (num2) Now if a class INTEGER is a descendant of NUMBER, it inherits "min", but the types of the argument and return value automatically change without explicit redefinition. So: class INTEGER inherit NUMBER end will give INTEGER a "min" function whose type is INTEGER, and whose argument must also be (or conform to) an INTEGER. So if I have: num1, num2, num3: NUMBER ; int1, int2, int3: NUMBER ; The following are legal: int3 := int1.min (int2) -- all types the same num3 := int1.min (int2) -- conforming result type num3 := num1.min (int2) -- conforming argument type but the following aren't: int3 := num1.min (num2) -- wrong result type int3 := int1.min (num2) -- wrong argument type I hope this helps. -- Rick Jones, Tetra Ltd. Maidenhead, Berks, UK rick@tetrauk.uucp Any fool can provide a solution - the problem is to understand the problem