Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site opus.UUCP
Path: utzoo!watmath!clyde!floyd!harpo!seismo!ut-sally!opus!rcd
From: rcd@opus.UUCP
Newsgroups: net.lang.mod2
Subject: Re: Cardinal
Message-ID: <206@opus.UUCP>
Date: Wed, 7-Mar-84 22:20:31 EST
Article-I.D.: opus.206
Posted: Wed Mar  7 22:20:31 1984
Date-Received: Fri, 9-Mar-84 01:05:32 EST
References: <5821@decwrl.UUCP> <2696@fortune.UUCP>
Organization: NBI, Boulder
Lines: 28

<>
 > . . . cardinals and integers
 > cannot be mixed in expressions.  This strikes me as a cop-out by Wirth.
 > Selecting a good rule for combining the two types in expressions
 > might be tricky [I haven't given it much thought],
 > but it seems analogous to the integer vs. floating-point combination
 > problem that has been around for years.
No, not a cop-out.  The problem is that you can't tell what the result type
should be.  The analogy with the conversion to floating point doesn't quit
work - normally there exists a floating point value which corresponds
correctly to every integer (possibly with some loss of accuracy if maxint
is larger than the fraction part can hold).  This means that floating point
can be treated as the 'dominant type' - whenever integral and floating are
combined, the result is floating.  But in the case of cardinals and
integers (of a given length, say), the ranges aren't nested, so there isn't
an obvious dominant type.  Should (integer+cardinal) be integral or
cardinal?  Some contexts are strong enough to tell - e.g., if the result is
assigned directly to a variable, use the type of the variable.  Not all
contexts have enough information to make the decision.

The situation you want to avoid is having to make some decision at runtime
as to the type.  I suspect that Wirth may have been thinking of this
problem, since an analogous glitch in Algol 60 created real problems.
(That is the situation of exponentiation, i^j, with i and j integral, in
which the result type is integral if j>0 and real if j<0.)
-- 

{hao,ucbvax,allegra}!nbires!rcd