Live data from Hacker News

Teal – A statically-typed dialect of Lua

teal-language.org

91–100 of 176 posts

Re: Teal – A statically-typed dialect of Lua

#91
post #59

Earlier quoted context omitted.

I don't think it's a good language, and I hate it. I've made thousands of the same mistakes with it—typing . instead of :. There's a reason Lua has a smaller audience than assembly.

> There's a reason Lua has a smaller audience than assembly. I don't think that's true. It's a very embedded language. Its use in video games and video game modding alone would outnumber the number of people directly writing assembly to achieve things.

It's also a very old embeddable language, which is probably most of why it's so often chosen for that purpose. Many similar languages have been written from scratch inspired by Lua over the last 10-15 years, some of them almost definitely better than Lua in many respects, but they get no traction because Lua has all the steam. Unfortunate, because the authors of Lua are fairly happy with semantic and syntactic decisions that many of us are very unhappy with.

Re: Teal – A statically-typed dialect of Lua

#92
post #90

Earlier quoted context omitted.

> 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?

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.

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.

Re: Teal – A statically-typed dialect of Lua

#93
post #85

I've been diving into Lua (a little late to this party, but turns out it's a perfect language to rewrite some commandline scripts I had that were getting unwieldy in Bash, especially with LLM assistance!) and it's really something of an eye-opener. LuaJITted Lua code runs at 80% (on average, sometimes faster!) of the compiled C version of the same algorithm , typically. Lua is embedded in a surprisingly massive numbe…

> LuaJITted Lua code runs at 80% (on average, sometimes faster!) of the compiled C version of the same algorithm, typically Cannot confirm this. It might be true on selected micro benchmarks. Here are the results of the Are-we-fast-yet benchmark suite, which includes a decent set of benchmarks challenging CPU, cache and memory access: https://github.com/rochus-keller/Oberon/blob/master/testcase... . On average, the C…

The code in Are-we-fast-yet has been heavily optimized. It might still be true that naive LuaJIT can run almost as fast as Naive C.

Re: Teal – A statically-typed dialect of Lua

#94
post #40

Earlier quoted context omitted.

> 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…

In reality, tables are used in specific fashions and not fully generally. (Partly because Lua itself even recognizes some of these fashions and provides relevant operations accordingly.) Lua tables are not really a single data structure; it is a single type that acts as multiple data structures at once.

Yeah Lua optimizes array tables for performance as long as they're arrays. That's the only optimization I'm aware of. I get why they didn't just add arrays, to keep the syntax and semantics clean, simple, and unambiguous. I just don't like it. If you take that to its extreme, you get Lisp. Natural human languages are messy and full of warts, but they work despite that, or perhaps because of that, because human life is messy and warty. "Pure" languages never can or do catch on. My favorite language right now is unironically TypeScript despite all its baggage.

Re: Teal – A statically-typed dialect of Lua

#95
post #69

I've been diving into Lua (a little late to this party, but turns out it's a perfect language to rewrite some commandline scripts I had that were getting unwieldy in Bash, especially with LLM assistance!) and it's really something of an eye-opener. LuaJITted Lua code runs at 80% (on average, sometimes faster!) of the compiled C version of the same algorithm , typically. Lua is embedded in a surprisingly massive numbe…

Any recommendations going from bash to lua to watch out for except indexing?

I haven’t found many downsides yet. I was already starting to rewrite some things in Awk (which I was drawn to for similar reasons- fast script startup time, simple easy language with good defaults), but Awk (while still also awesome) isn’t really designed for stuff beyond a certain size (no signal handling unless you use a fork, for example)

LuaJIT is missing bignums, ints that aren’t floats, bit operations, and native utf8 handling, but it can pretty easily be extended with libraries, ffi and metatabling. (I actually made a working bignum library that integrates with gmp, but it has a memory leak somewhere and it’s a rabbit hole/bikeshedding project at this point…)

LLM assistance helps hugely and I really like YueScript’s syntax additions. You can point any LLM at a syntax describing webpage and it will pretty much write that language for you…

Re: Teal – A statically-typed dialect of Lua

#96

Earlier quoted context omitted.

It is true that LuaJIT is stuck at 5.1, but you could write any performance critical sections in C/C++ and call it from Lua. Lack of LuaJIT for 5.1+ isn't that big of a deal for desktop apps. The embedded world is still stuck in 5.1, but for them, the benefits of the latest Lua is marginal.

And despite it being stuck at 5.1, it still implements features from other versions. For example, there is the "LJ_52" macro, so you can compile "table.pack" and "table.unpack" into LuaJIT, which I do, because I use both at times. As someone else have pointed it out, they are cherry picked: https://luajit.org/extensions.html .

There is also the compat53 library which polyfills most of the missing parts. The Teal compiler has --gen-target and --gen-compat flags which adapts the generated Lua code for different Lua versions, and allows using the compat53 library behind the scenes if desired, so you can get a mostly Lua-5.3+ experience over LuaJIT using Teal.

Re: Teal – A statically-typed dialect of Lua

#97
post #3

I'm so relieved to see more types being added to good languages. So Teal is to Lua as TypeScript is to JavaScript. Which means it automatically plays well with any Lua environment. Unlike luau and nelua which are also statically typed but have their own runtimes. What version of Lua does it use? Lua gets new versions every few years so I don't know why so many impls don't continuously upgrade to the latest version.

Teal currenly supports generating code for Lua 5.1 and up, including LuaJIT. There are compiler flags --gen-target and --gen-compat which control various specifics of code generation.

Re: Teal – A statically-typed dialect of Lua

#98
post #39

I really love teal! Here is a 10k loc project I have in it - https://github.com/Koeng101/libB/blob/dev/src/dnadesign/dnad... - Basically, I reimplemented all my synthetic biology bioinformatics from Go into teal so that LLMs can script with it better in a hermetic environment. It's got all sorts of things like cloning simulation, codon optimization, genbank parsing, synthesis fixing, reliable sequence hashing, sequen…

Teal creator here! Thank you for the kind words, super happy to see people being productive with it!!

On your wishlist items:

1. There are a few third-party projects that bundle Lua code. One that comes to mind is https://lrocket.codeberg.page/ — I don't know if this functionality should be brought into Teal itself, it sounds to me like something better left to the surrounding tooling?

2. Unfortunately those annoyances are part of the heterogeinity of the Lua ecosystem, but Teal tries to paper over them using the compat53 library (which, granted, is not available everywhere if you want to do a pure-Lua deployment on existing Lua environments). The --gen-target and --gen-compat flags should still help some, hopefully!

3. Not sure what you mean there -- you mean adding chunks of untyped Lua _in the same file_? I think that if you have a json.lua and a json.d.tl file, then it should use the definition file only and leave the .lua file alone. At least that's the intended behavior!

4. That's up to GitHub :) Last time I checked their docs I think they want something like 100 or 200 projects using the language for considering adding native highlighting for it on the website. But you can add a .gitattributes file to the root of your repository like this https://github.com/teal-language/tl/blob/master/.gitattribut... and at least it will display .tl files with .lua highlighting.

Again, thank you so much for the feedback!

Re: Teal – A statically-typed dialect of Lua

#99
post #85

Earlier quoted context omitted.

> LuaJITted Lua code runs at 80% (on average, sometimes faster!) of the compiled C version of the same algorithm, typically Cannot confirm this. It might be true on selected micro benchmarks. Here are the results of the Are-we-fast-yet benchmark suite, which includes a decent set of benchmarks challenging CPU, cache and memory access: https://github.com/rochus-keller/Oberon/blob/master/testcase... . On average, the C…

The code in Are-we-fast-yet has been heavily optimized. It might still be true that naive LuaJIT can run almost as fast as Naive C.

Have a look at the results and the code; there are benchmarks in the suite where the (ideomatic) C/C++ implementation is "only" twice as fast as the corresponding (idiomatic) Lua implementation, but on average (geomean of all factors) it's about five times as fast. The guidelines of the benchmark are pretty strict to enable fair comparisons (see https://github.com/smarr/are-we-fast-yet/blob/master/docs/gu...).

Re: Teal – A statically-typed dialect of Lua

#100
post #22

This is super cool. I have been using TypeScript To Lua ( https://github.com/TypeScriptToLua/TypeScriptToLua ) for a little game side project and it works quite well, I am pleased with it. It does end up generating a lot of Lua code though because it has to support all of TypeScript’s features, which isn’t ideal. I’d expect Teal’s output to be much more concise Lua which has me interested.

Teal's output is currently pretty much 1-to-1 with the input apart from removing all of the type information of course. (I've been trying hard to keep it that way so that the error messages in stack traces match the input lines without having to do source mapping.)
Post reply on HN