Live data from Hacker News

Teal – A statically-typed dialect of Lua

teal-language.org

31–40 of 176 posts

Re: Teal – A statically-typed dialect of Lua

#31
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.

Each new Lua version has breaking changes that are of dubious value to keep on the upgrade treadmill. Something like a Python2->3.

LuaJIT is famously on 5.1 with no signs of moving.

Re: Teal – A statically-typed dialect of Lua

#32
post #8
post #5

Oh, clever name. Typed Lua → TL → "Tee Ell" → Teal And the extension is .tl

Off-topic comment, but as an ESL speaker I just this week randomly learned that teal the color is named after the duck species Anas crecca , called (edit: common or Eurasian) teal in English.

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.

Re: Teal – A statically-typed dialect of Lua

#33
post #9
post #6

Earlier quoted context omitted.

Lua is a good language. It's like C, if C were a scripting language. It's got an awesome C API. It's fast, lightweight, and embeddable. It's more performant than Python. It's a staple in video game scripting.

It's nothing like C, and that's so much of its charm. Semantically, Lua is almost identical to the core of JavaScript. Metatables are a genius alternative to prototype chains. Lua's syntax is beautifully simple and unambiguous, but at the cost of being moderately inconvenient in 2025 unfortunately. It could benefit from an ESNext-style renewal. I get why they made the C API that way, but in practice it's very easy to…

FYI, for those who may not be aware, moonscript is the "coffeescript" for lua. It has been in production use for quite a while (the author of moonscript also created itch.io, using ... moonscript).

yuescript, from the dora-ssr game engine dev, is essentially moonscript-2.0

And of course, if you want to treat lua as the scheme-like it really is (deep down), then ... fennel.

Lots of choices. They all compile to straightforward lua, are very easy to incorporate (you can even compile at runtime, if you wish), and all employ full lua semantics, meaning zero runtime overhead

EDIT: and the curse of not reading fully ahead strikes again (doh!). Someone else has made the same points below ...

Re: Teal – A statically-typed dialect of Lua

#34
post #20

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

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 frameworks and libraries, but are also required to use language features like @dataclass.

Re: Teal – A statically-typed dialect of Lua

#37
post #8

Earlier quoted context omitted.

Off-topic comment, but as an ESL speaker I just this week randomly learned that teal the color is named after the duck species Anas crecca , called (edit: common or Eurasian) teal in English.

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 for a long time, and most color names are comparatively recent inventions, driven by modern dyes and pigments and status, fashion, etc concerns. A West European peasant in the 11th century would’ve known the bird well, possibly trapped them for food, but would’ve had very little need for a separate word for ”blue-green”.

The history of color words is quite interesting. There’s a specific progression that almost all languages have gone through. It’s fairly well known that many East Asian languages don’t have separate names for ”blue” and ”green” at all (except as modern loans). Accordingly, they don’t usually make the distinction mentally, one could think that they simply consider them hues of ”cyan”.

Re: Teal – A statically-typed dialect of Lua

#38

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

> How confident are you in the soundness of the type system?

Teal's types are hints, like Python's and TypeScript's, so I suspect it's not sound by design.

> Also, are there any Lua constructs that are difficult/impossible to type?

Teal includes several types that model typical uses of Lua tables, e.g. as arrays, maps etc. It doesn't look like it can type fully general use of Lua tables, e.g. using both the "array part" and "hash part" of the same table.

Re: Teal – A statically-typed dialect of Lua

#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, sequence analysis, etc. I'm pretty sure it is a more complete synbio library than anything in python, actually.

A couple things I want from teal: 1. I wish there was a better way to bundle files together. I have a little build.lua, but eh, I think it could be better. I know of cyan and everything but I feel like that was developed for a different application than mine. I want to have 1 complete file that I can just give people and allow them to do synbio work in any target language with a lua machine. 2. There are some annoyances around luajit vs lua5.1 functionality 3. The compiler yelling at you gets old for integrating raw lua. I tried to port json.lua in and even with the definition file, I couldn't embed the whole json.lua without having compiler errors. So eventually I just imported it as a string that is type checked, which is bad 4. I really wish syntax highlighting on github was a thing

The good bits:

It's pretty much complete. I used it a couple years ago and there were things with generics that I just couldn't do, but now it is much better. For example, how I use generics for the different parsers (fastq, fasta, genbank, slow5, pileup, etc) https://github.com/Koeng101/libB/blob/dev/src/dnadesign/src/...

Overall, love it! It is one of those pieces of software which is nearly complete, and I love using software like that.

Re: Teal – A statically-typed dialect of Lua

#40
post #27
post #20

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

> 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 to change radically - adding a type checker would invalidate the current approach of using a single-pass source-to-bytecode compiler.

Post reply on HN