[Types-sig] recursive types, type safety, and flow analysis

skaller skaller@maxtal.com.au
Thu, 23 Dec 1999 11:14:44 +1100


Paul Prescod wrote:
 
> a.py:
> 
> a=5
> 
> if something():
>         a = 5
> elif somethingElse():
>         a = "abc"
> elif somethingElse2():
>         a = 32L
> elif somethingElse3():
>         a = ["ab"]
> else:
>         del a

	The type of a is one of:

	int, string, long, tuple, or terminal

where 'terminal' means 'a doesn't exist'.
 
> b.py:
> 
> import a
> a.a = "jab"

	module attribute assignment is banned

> c.py:
> 
> import a
> a.a = ("abc",5)

	module attribute assignment is banned
 
> d.py:
> 
> import a, b, c
> 
> j: Int
> j = a.a
> 
> What's the error message? 

	There isn't one at compile time.
a could be an int, the inference engine cannot 
know if it is or not, so it keeps quiet.
At run time, a TypeError is raised if something
other than int is assigned.

	[Yes, I know I changed the rules on you
by saying the module attribute assignments were banned]

	Note: Viper will do better than this
compiling whole programs. It loads modules dynamically at 
compile time, by running the interpreter, so all modules
are fully built at compile time.

	Then, it is easy to know not only the types
of every (module) variable, but also their values!
Obviously, this will not work on a 'per module' basis.

-- 
John Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850