[Compiler-sig] Type checking

John Max Skaller skaller@maxtal.com.au
Tue, 09 May 2000 15:37:11 +1000


Charles E Jenkins wrote:
> 
> Hello to all. I hope this is the correct forum for asking about the whys and
> wherefores of Python compilation.
> 
> I, too, am interested in seeing strong type-checking added to the language. I
> wonder what technical reasons prevent strong runtime type-checking from being
> added.
> 
> Here's how naive I am. I would think it would be as easy as
> 
>         def myFunc1( num is IntType )
>         def myFunc2( any_list is ListType )
>         def myFunc3( string_list is ListType of StringType )
> 

	Vyper implements this right now.
	The syntax is to use operator ! rather than 'is':

	def myFunc1 ( num ! IntType): ...

You can also check expressions:

	x = value ! IntType # raises TypeError if value isn't an int

> I call myself naive because this is so easy that there must be a very good
> reason why Python doesn't have these facilities!

	Politics. I implemented the above operator, whose design
is attributed to Greg Stein in a couple of days.

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net