Path: utzoo!attcan!uunet!clyde.concordia.ca!mcgill-vision!snorkelwacker!tut.cis.ohio-state.edu!cs.utexas.edu!mailrus!ncar!boulder!gore!jacob From: jacob@gore.com (Jacob Gore) Newsgroups: comp.object Subject: Re: inheritance and `type loss' Message-ID: <1130013@gore.com> Date: 12 Jul 90 15:58:47 GMT References: Reply-To: jacob@gore.com (Jacob Gore) Organization: Gore Enterprises Lines: 52 / comp.object / sra@ecs.soton.ac.uk (Stephen Adams) / Jul 10, 1990 / Let me try this again, since what I said before makes no sense to me either... I'm only talking about the effect of inheritance on the problem, so I assume that the language does not use double dispatching, upward coersion, or overloading (i.e., there is only one "+" operation per class). > + which takes another integer and returns the sum > image which returns a string denoting the integer > as a decimal number > > so 2+4 -> 6 and (6).image -> "6" I also assume that "2+4" means "(2).add(4)". Now, since the compiler does no implicit type conversion, the type of the result and the operand of each operation depends on the programmer of that operation, rather than by the compiler. So, here's how I'd do it: > (a) what should (V+V).image yield? "10" or "X"? I would define "+" as: + : Like Self x Like Self --> Like Self so "V+V" returns a roman, hence (V+V).image returns "X". > (V+1).image "6" or "VI"? With my definition of "+", this would be an error. "Like Self" is Roman for V, and an Integer is not an acceptable replacement for a Roman. (Of course, if this was a common enough operation, "+" would be better defined as +: Like Self x Integer --> Like Self or +: Like Self x Integer --> Integer.) > (1+V).image "6" or "VI" or error (in +)? This would return "6". "Like Self" is Integer, so no conversions are needed: V is a Roman and hence an Integer. There are, of course, many other ways of doing it. I feel this one is most natural for the set of assumptions that I made. Jacob -- Jacob Gore Jacob@Gore.Com boulder!gore!jacob