What is a type error?

Pascal Costanza pc at p-cos.net
Thu Jun 22 09:59:29 CEST 2006

Chris Smith wrote:

> While this effort to salvage the term "type error" in dynamic languages 
> is interesting, I fear it will fail.  Either we'll all have to admit 
> that "type" in the dynamic sense is a psychological concept with no 
> precise technical definition (as was at least hinted by Anton's post 
> earlier, whether intentionally or not) or someone is going to have to 
> propose a technical meaning that makes sense, independently of what is 
> meant by "type" in a static system.

What about this: You get a type error when the program attempts to 
invoke an operation on values that are not appropriate for this operation.

Examples: adding numbers to strings; determining the string-length of a 
number; applying a function on the wrong number of parameters; applying 
a non-function; accessing an array with out-of-bound indexes; etc.

>> In the terminology I'm suggesting, the object has no type in this language
>> (assuming we're talking about a Smalltalk-like language without any type system
>> extensions).
> I suspect you'll see the Smalltalk version of the objections raised in 
> response to my post earlier.  In other words, whatever terminology you 
> think is consistent, you'll probably have a tough time convincing 
> Smalltalkers to stop saying "type" if they did before.  If you exclude 
> "message not understood" as a type error, then I think you're excluding 
> type errors from Smalltalk entirely, which contradicts the psychological 
> understanding again.

Sending a message to an object that does not understand that message is 
a type error. The "message not understood" machinery can be seen either 
as a way to escape from this type error in case it occurs and allow the 
program to still do something useful, or to actually remove (some) 
potential type errors. Which view you take probably depends on what your 
concrete implementation of "message not understood" does. For example, 
if it simply forwards the message to another object that is known to be 
able to respond to it, then you remove a potential type error; however, 
if it pops up a dialog box to ask the user how to continue from here, it 
is still a type error, but just gives you a way to deal with it at runtime.


3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006

More information about the Python-list mailing list