Re:Type checking in Python
by gsg on Sunday May 18, 2014 @01:42PM
(#7763684)
It's not hard to imagine an extension to ML-style types that could cover variadicity:
Where <type>... denotes <type1> -> <type2> -> ... -> <typeN> spliced into the type signature, with each type variable 'a in <type> replaced with 'a1, 'a2, ... 'aN. You could cover tuples too:
Bit ugly, and writing a type checker for it could be fun, but it seems workable.
[ Parent
| on HN ]
Take a look at Typed Racket for a variation on this.
http://docs.racket-lang.org/ts-guide/types.html?q=typed#%28p...
Right, looks very similar.
Typed Racket is pretty decent.
However, behold the byzantine Scheme numerical tower and the effort to type it: http://www.ccs.neu.edu/home/stamourv/papers/numeric-tower.pd...
Fully typing variadicity in Python is only possible with dependent typing, since Python allows you to build the argument list dynamically. Generally speaking you can't even determine the number of arguments statically:
args = []
while some_condition():
args.append('x')
f(*args)
Typed Racket allows you type some common cases, though.