include
statement, cannot resolve this
problem. For example, if we rename B's secret to
secret2, the program will print two 2's. But at least
Sather warns us of the problem. In Python and Self, the program would
happily print two 2's. We think forwarding is a safer way to share code.
typecase
cannot be removed by overloading. If class
FOO
chose the signature is_eq(k : FOO) :
BOOL
, then it wouldn't be conforming to the $IS_EQ
class type, and the compiler would report an error. This is also a
problem in C++, but C++ does not have a typecase
to
remedy it.
Another response to this situation is FOO
is
allowed to use a more specific signature than specified by its type.
However, this admits the possibility of a run-time type error.
In order to avoid run-time type errors, Sather has chosen the opposite
rule: FOO
is
allowed to use the same or more general signature than specified by
its type. (C++ uses
(Aside: these five-dollar words are more expensive than the concepts they represent. We prefer "specialization" to "covariance" and "generalization" to "contravariance".)
To check if an object O is a member of type T,
we check if O type
, or some parent of O
type
, is T
.
We will see an explicit type system of this sort in the Life language.