Teal – A statically-typed dialect of Lua
41–50 of 176 posts
Re: Teal – A statically-typed dialect of Lua
#42This is very cool. I wonder if it works with Roblox, which is probably the environment with the largest number of Lua programmers. It certainly looks like it should work basically anywhere Lua works.
It is gradually typed, so no need to use Teal.
Re: Teal – A statically-typed dialect of Lua
#43Earlier quoted context omitted.
Just a small note about mypy and python - annotations are first-class citizens in Python3 and are not tied to any particular type checking system such as mypy, but are instead a core part of the language and actually serve vital functions in frameworks and libraries that are used to check interfaces such as Pydantic and FastAPI (eg URL params). Mypy is just one type checker for Python, but there are many others inclu…
Am I right in thinking that Python's type annotation syntax originally came from Mypy though? IIRC Mypy started off as a type annotation syntax and corresponding type checker for Python. Mypy's type annotations were adopted by Python itself (in version 3.5 - PEP 484), which reduced Mypy's role to be just a type checker. Since then, type annotations have indeed become a core part of Python - not only are they used in…
https://peps.python.org/pep-3107/
MyPy was one such tool, and I think it had conventions for adding type annotations in comments, in places where Python didn't yet support them (such as variable assignment), but I'm pretty sure it was never a TypeScript-style pre-processor - type-annotated programs always ran directly in the unmodified CPython interpreter.
Re: Teal – A statically-typed dialect of Lua
#44> Teal is a statically-typed dialect of Lua. I was expecting Teal to be "Lua + type annotations", similar to Mypy. However from a quick look it does indeed seem to be a "dialect" in its own right. Teal is Lua-like and compiles to Lua, but there's more to it than just static types. Perhaps it's more similar to TypeScript? For example, Teal replaces Lua's tables - the language's signature single, highly-flexible data s…
By ambitiously adding useful features, could Teal push the upstream to make progress? Probably not because Lua's scope is intended to be small (and we're no longer in the same context as 2015 era Typescript and tc39), but it's interesting to think about.
Re: Teal – A statically-typed dialect of Lua
#45Earlier quoted context omitted.
> Teal replaces Lua's tables - the language's signature single, highly-flexible data structure - with separate arrays, tuples, maps, records and interfaces They're all just Lua tables with specialized type checking for specific behavior. I really wish the Lua authors would add official types to Lua. The time has come.
> I really wish the Lua authors would add official types to Lua. Never going to happen IMO. Adding static types would change the nature of the language completely, even more than it has in Python. As Teal shows, it would require giving up one of Lua's core features: tables as the language's single data structure. It would significantly complicate a language known for its simplicity. Even the implementation would need…
> Never going to happen IMO. Adding static types would change the nature of the language completely, even more than it has in Python.
You both are kind of right.
The Lua authors have been working on the new companion language to Lua named Pallene. Pallene is a subset of Lua that adds types, not for the sake of types themselves, but for the purpose of performance. The Pallene compiler can generate optimized native code that potentially removes the need to manually write a module for Lua in C.
The other cool trick is that Pallene and Lua are completely interoperable with each other, so Pallene can be added to existing Lua projects, and you can opt to use regular Lua for the dynamic parts of your code where compilers won't be able to optimize much and strong types might be more trouble than help.
Here is a talk Roberto Ierusalimschy gave about Pallene. https://www.youtube.com/watch?v=pGF2UFG7n6Y
Re: Teal – A statically-typed dialect of Lua
#46How confident are you in the soundness of the type system? Also, are there any Lua constructs that are difficult/impossible to type? Is type checking decidable? (Is the type system Turing complete?)
* Your type system cannot be sound. It's going to have escape hatches and exceptions because that's how dynamic languages roll.
* There will always be constructs that you can't type. See above.
* If your type system is going to usefully type enough of the ecosystem, it will be Turing complete.
All of these things are the trade-offs you make when you set out to layer types on a dynamic language, and they're well worth it to get 99% of the way to type safety in a language that otherwise couldn't scale. Theoretical purity is meaningless if the language isn't useful.
Re: Teal – A statically-typed dialect of Lua
#47Has anyone used this? Any reviews? Based on the Github issues, the type system seems to have some holes in it, but it's not obvious how bad is it in real world.
Re: Teal – A statically-typed dialect of Lua
#48> Teal is a statically-typed dialect of Lua. I was expecting Teal to be "Lua + type annotations", similar to Mypy. However from a quick look it does indeed seem to be a "dialect" in its own right. Teal is Lua-like and compiles to Lua, but there's more to it than just static types. Perhaps it's more similar to TypeScript? For example, Teal replaces Lua's tables - the language's signature single, highly-flexible data s…
It's interesting that you mention Typescript. In Typescript's early history, they added a bunch of features that they either thought would make it nicer for C# devs (classes, enums, option chaining, decorators, namespaces, etc.). Eventually, a bunch of these features were added to Javascript natively in nearly the exact same way they were implemented in Typescript. Now, the only remaining non-type-related features no…
Re: Teal – A statically-typed dialect of Lua
#49How confident are you in the soundness of the type system? Also, are there any Lua constructs that are difficult/impossible to type? Is type checking decidable? (Is the type system Turing complete?)
People get this way about TypeScript too, and it always perplexes me. These projects are about adding types to untyped languages, and that comes with a few givens: * Your type system cannot be sound. It's going to have escape hatches and exceptions because that's how dynamic languages roll. * There will always be constructs that you can't type. See above. * If your type system is going to usefully type enough of the…
I think you could prove that you can't construct a sound & complete type system for Lua. But just saying "Your type system cannot be sound" by itself is definitely wrong. I don't understand why people are throwing out both soundness & completeness, instead of at least retaining one (and I think the choice here is pretty obvious, a sound but incomplete type system is much more useful than an unsound one).
From Flow's website[1] (a type checker for JavaScript):
> Flow tries to be as sound and complete as possible. But because JavaScript was not designed around a type system, Flow sometimes has to make a tradeoff. When this happens Flow tends to favor soundness over completeness, ensuring that code doesn't have any bugs.
I don't understand why other type systems for dynamically typed languages cannot strive for that, and in particular I am pretty salty at TypeScript for explicitly not caring about soundness.
[1]: https://flow.org/en/docs/lang/types-and-expressions/#toc-sou...
Re: Teal – A statically-typed dialect of Lua
#50Earlier quoted context omitted.
TIL! My wife is a photographer and she's been photographing a ton of Blue-winged Teals over the last couple months during their migration. I assumed that the ducks had been named after the color.
Cool! (Just to be clear, I meant the common, or Eurasian, teal whose iridescent green head markings the color’s apparently named after. The NA teals are closely related, although it seems they were assigned to their own genus in 2009 as it was discovered that the then- Anas was not monophyletic.) Generally colors are named after things in nature and not the other way around, given that the latter would’be had names f…
https://en.wikipedia.org/wiki/Blue%E2%80%93green_distinction...