[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optional types
Date: 07 Dec 2001 12:26:37 -0500
From: Eric Kidd <eric.kidd@pobox.com>
Dylan's approach might be summarized as:
"A vector which happens to contain nothing but integers is not the same
thing as a vector-of-integers."
The first has the type '<vector>', the second, 'limited(<vector>, of:
<integer>)'.
Another approach that one might take here would be to draw a greater
distinction between "class" and "type". (When I was reviewing drafts
of the Java Language Spec, this was something I talked about a lot;
the released spec has a section entitled "Variables Have Types,
Objects Have Classes" that talks about this.)
What you might do is say that the first is of class '<vector>', and
the second is of class 'limited(<vector>, of: <integer>)'. But types
need not correspond in a one-to-one-onto way with classes (as in the
Curl example I mentioned recently).
So you could have a type which means "the value of this variable must
be an object that obeys the defined protocol (contract) of a vector,
and furthermore every element of the vector must be an integer".
Obviously there are tradeoffs here; the more your type language can
express things beyond "the value of this variable is an object of
class X", the more you need a whole syntax and semantics of types that
goes beyond the syntax and semantics of classes. I guess you could
think of such a type language as being a "little language" (in the
sense that Olin uses the phrase), a special-purpose declarative
language for writing certain assertions that turn out to be frequently
useful.