Closed shviller closed 2 years ago
Ah, this form for <vars> in <fn>, <args> do
was supposed to work in Teal, and in fact it does with plain iterator functions. It only failed with next
because it is a "special" polymorphic function (i.e., with two type signatures in the Teal standard library definition, one for maps and one for arrays). Adding a case for poly
types made the example above work.
Typechecking the following code
leads to this error:
However, barring its redefinition (or the presence of the
__pairs
metamethod in Lua 5.3 and up), usingpairs(t)
is actually equivalent to providing those three values (next,t,nil
) directly. People have been using this specifically to avoid the metamethod, but, of course, that's not the only use. I myself tried to use it grab the first value out of a table if the initial value forreduce
isn't provided:This isn't a dealbreaker in any way, since such functions can always be kicked out into a separate Lua file, but it would be nice to have it in Teal.