[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strong Typing, Dynamic Languages, What to do?



Shriram Krishnamurthi <sk@cs.brown.edu> writes:

> Define a new type, A.
> 
> Define a vector of ten A's.
> 
> Make an instance of this vector.
> 
> C++'s type system says that all dereferences of this vector will give
> you objects of type A.
> 
> Dereference the eleventh element of this vector.
> 
> Do you get an A?

No.  But if you want range checking, you can access elements of the
vector with the at() member function, which throws an exception for an
out of bounds access.

That leads to an interesting philosophical question: should range
checking be considered part of a type system?  

To me this has a langauge dependent answer, and if for the langague
the answer is "no" (like in C++), then I am not sure that an
out-of-bounds access should be considered a failure of the type
system.  (Maybe it could be argued a failure in language for other
reasons though.)

-- 
Chris