Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!inria!imag!mururoa!marat.osf.fr!macrakis From: macrakis@marat.osf.fr (Stavros Macrakis) Newsgroups: comp.lang.eiffel Subject: Re: Real,Complex,Inheritance and Subtyping Message-ID: <96@mururoa.imag.fr> Date: 16 Jan 90 11:01:08 GMT References: <32770@news.Think.COM> <1526@castle.ed.ac.uk> Sender: news@imag.fr Reply-To: macrakis@marat.osf.fr (Stavros Macrakis) Organization: OSF Research Institute Lines: 34 In article <32770@news.Think.COM>, barmar@think.com (Barry Margolin) writes: > In article <1526@castle.ed.ac.uk> db@lfcs.ed.ac.uk (Dave Berry) writes: > >The class Complex can be defined using two attributes of class Real. Are > >there any languages in which it is then possible to make Real a subtype of > >Complex? Is this an example when subtyping should be separated from > >inheritance? > > If anyone were to try such a thing, I'd think they were doing it backwards. > Types in programming languages generally model sets in mathematics, and > real numbers are a subset of complex numbers, so it would make more sense > for the type Real to be a subtype of Complex. Reals are just those > Complexes whose imaginary part is 0. The relationship between the complex numbers and the reals can indeed be seen from two different perspectives: one, the reals are a special case (a subset, if you like) of the complex; the other, the complex are constructed from the reals. Neither is more correct, either in mathematics or in programming. Indeed, each approach has its strengths and its weaknesses. If you take the "subset" approach, then perhaps you should model the complexes as a subset of the quaternions, or of the square matrices, etc. etc. If you take the "construction" approach, perhaps you should model complexes in polar form, or as two infinite bit-vectors, or as a pair of integer/fraction parts. Both are incomplete views. In particular, it's really not the "subset" property that matters, but the "substructure" property. (there's the classic article "Why Data Types are Not Sets" which appeared in Sigplan Notices about 12 years ago which goes into more detail-- sorry, I don't have the reference). -s