4 ms·
It's not hard to imagine an extension to ML-style types that could cover variadicity: map : ('a... -> 'b) -> ('a list)... -> 'b list Where <type>... denot
by gsg 12y ago
It's not hard to imagine an extension to ML-style types that could cover variadicity:
map : ('a... -> 'b) -> ('a list)... -> 'b list
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:
zip : ('a list)... -> 'a,,, list
Bit ugly, and writing a type checker for it could be fun, but it seems workable.
- tel 12y agoTake a look at Typed Racket for a variation on this.
- gsg 12y agohttp://docs.racket-lang.org/ts-guide/types.html?q=typed#%28part._varargs%29 http://docs.racket-lang.org/ts-guide/types.html?q=typed#%28p... Right, looks very similar.
- xiaq 12y agoTyped 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.pdf http://www.ccs.neu.edu/home/stamourv/papers/numeric-tower.pd...
- xiaq 12y agoFully 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.