[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Type Specifier: (OR (FUNCTION ...) ...)
Date: Sat, 19 Apr 1986 16:24 EST
From: "Scott E. Fahlman" <Fahlman@C.CS.CMU.EDU>
To: NGALL@BBNG.ARPA
Subject: Type Specifier: (OR (FUNCTION ...) ...)
In-Reply-To: Msg of 18 Apr 1986 16:07-EST from NGALL at G.BBN.COM
Message-ID: <FAHLMAN.12200153421.BABYL@C.CS.CMU.EDU>
Regarding your proposal that we allow forms like the following
(or (function (list) list)
(function (vector) vector))
as a way of specifying that the output type of a function matches its
input type...
It seems to me that there are a lot of things one might want to tell a
compiler about the type relationships between the arguments to a
function and its values. For example, + performed on a positive fixnum
and a negative one is sure to return a fixnum, so no bignum check is
required.
Under my proposal, the above constraint could be declared as follows:
(proclaim '(ftype (or (function ((integer 0 #.most-positive-fixnum)
(integer #..most-negative-fixnum 0))
fixnum)
(function (&rest number) number))))
Of course, other constraints (e.g., + performed on integers results in
an integer) could be included also. One constraint that could not be
directly declared is that + performed on N rationals one of which is a
float results in a float. But since most compilers transform the
multi-argument versions of functions into equivalent nested two-arg
version, enumerating the two-arg type combinations would suffice.
Your proposal seems to take one small step in the direction
of such a declarative language, and then it stops.
Could you give me an example of the further steps you would like to see?
If it were clear
that the extra cases your mechanism handles are the most common and
important ones, then I'd favor adding this special case, but it isn't
clear to me. Also, it gets into all the issues raised by the
Commonloops type-precedence stuff. If someone were to say
(or (function (list sequence) foo)
(function (sequence list) bar))
then what do we do?
According to the definition of the OR type-spec on pg. 45, "it always
tests each of the component types in order from left to right and
stops procesing as soon as one component of the union has been found
to which the object belongs."
Once the object-oriented stuff settles a bit, maybe
the answer will be clear.
-- Scott
--------------------
-- Nick