Hi, I do not want to discourage Philippe Fremy but I think that this would be very very difficult to do without modifying Python itself.
What FP languages rely upon to achieve type inference is a feature named "strong typing". A clear definition of strong typing is : "Every well-formed expression of the language can be assigned a type that can be deduced from the constituents of the expression alone." Bird and Wadler, Introduction to Functional Programming, 1988 This is certainly not the case for Python since one and the same variable can have different types depending upon the execution context. Example : 1- if a is None: 2- b = 1 3- else: 4- b = "Phew" 5- b = b + 1 One cannot statically determine the type of b by examining the line 5- alone. Therefore, Fremy's dream can very well turn to some very complex expert system to make "educated" warning. Being "educated" is a lot harder than to be "brutal". It's funny that what mainly prevents us from easily doing a type inferencer is at this very moment discussed with almost religious flame in the "variable declaration" thread. Anyway, strong typing as defined above would change the Python language in some of its fundamental design. It would certainly be valuable to attempt the experience, and rename the new language (mangoose would be a pretty name). Francis Girard FRANCE Le mardi 1 Février 2005 16:49, Diez B. Roggisch a écrit : > > But it can be useful to restrict type variety in certain situations > > e.g. prime number calculation :) And it would probably also be useful > > to check violations of restrictions before running the program in > > normal mode. > > But that's what (oca)ml and the like do - they exactly don't force you to > specify a type, but a variable has an also variable type, that gets > inferned upon the usage and is then fixed. > > -- > Regards, > > Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list