←back to thread

218 points generichuman | 2 comments | | HN request time: 0.417s | source
Show context
pansa2 ◴[] No.44001141[source]
> 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 structure - with separate arrays, tuples, maps, records and interfaces. It changes the variable scoping rules and even adds macro expressions.

Teal therefore seems substantially more complex than Lua. The author recognizes this in the conclusion to a recent presentation [0]: Lua is "small and simple", maybe Teal is "something else"? Lua is for "scripting", maybe Teal is better suited to "applications/libraries"?

[0] https://youtu.be/Uq_8bckDxaU?t=1618

replies(8): >>44001173 #>>44001256 #>>44001260 #>>44001346 #>>44001369 #>>44001755 #>>44004680 #>>44006829 #
90s_dev ◴[] No.44001346[source]
> 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.

replies(1): >>44001641 #
pansa2 ◴[] No.44001641[source]
> 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 to change radically - adding a type checker would invalidate the current approach of using a single-pass source-to-bytecode compiler.

replies(3): >>44001873 #>>44002336 #>>44004473 #
tiffanyh ◴[] No.44004473[source]
> As Teal shows, [official typed Lua] would require giving up one of Lua's core features: tables as the language's single data structure.

Is that true ... you can't have typed tables without giving up tables as a data structure?

replies(1): >>44004879 #
1. krapp ◴[] No.44004879[source]
You can't have typed tables without giving up tables as the language's single data structure. You would have tables and typed tables which are essentially just arrays with extra steps.
replies(1): >>44005027 #
2. 90s_dev ◴[] No.44005027[source]
Not with type erasure like TypeScript does. Then it would just be type checking hints as to how the table is used, not a different kind of table. Teal does this.