[Types-sig] type-safe declaration

Paul Prescod paul@prescod.net
Mon, 13 Dec 1999 22:44:38 -0800


> > #4. There must be declarations that instruct static type checking
> > software to verify that a function cannot violate binding assertions.
> > These are called safety declarations.
> 
> I'm not sure what you mean here and how such declarations differ from
> type assertions.  And I'm worried about the "must" part.  Please explain
> better?

"must" is an instruction to the specification writers (us) not to Python
programmers. It means that we must provide a mechanism that would allow
a programmer to say that a function is type-safe:

type-safe
StringType
def double(a):
	StringType, a;

	return a*a

Unlike Java, if you don't ask for a function to be statically type
checked then it just isn't. Newbies can work without type checking until
they feel it would be useful for them.

My feeling that declaring a return type is just declaring a return type.
It doesn't mean that you are willing to PROVE (statically) that the
return type declaration will be accurate.

> But I'd still like to be able to be diagnosed at compile time instead
> of at runtime when my code makes a statically illegal call to a
> function with a safety declaration.

Under my plan, you would need a static declaration on YOUR code. I mean
if your code can NEVER be right (e.g. range( "abc" ) ) then maybe a
smart checker could report that. Java actually requires this of
implementors. But if your code COULD be right (which is much more often
the case in Python) then it should wait until runtime to check:

a=callSomeUnTypedFunction()
range( a )

> OK.  I'm not sure everywhere whether you want compile-time or run-time
> checking.  Perhaps you can clarify this?

Static type checking if you ask for it (with a type-check declaration)
or dynamic type checking otherwise (unless you turn it off with an
optimization option).
-- 
 Paul Prescod  - ISOGEN Consulting Engineer speaking for himself
Three things to be wary of: A new kid in his prime
A man who knows the answers, and code that runs first time
http://www.geezjan.org/humor/computers/threes.html