lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, May 12, 2023, at 21:50, Mouse wrote:
>>> I think it's a bad idea to have type information that isn't
>>> enforced.
>> The idea is not not to enforce them.  The idea is that you can have a
>> dynamic language with statically checked types.
>
> Sooner or later something will be changed and the dynamic type won't
> match the static annotation.  Without enforcement, there's no easy way
> to catch this.

Of course there is an easy way to catch it: run the type checker.

If you add type annotations to your code it's because you use a type 
checker. You can ask other contributors to use it too, and you can add
it as an integration test - for instance if you use GitHub with a
GitHub action.

But the language interpreter itself can remain simple and unconcerned 
with type checking, and end users can run the program unmodified
without overhead (and without a "type stripping" step that comes with
its own problems).

Also, once you have something like that, you *can* use it to do things 
at runtime. For instance, you can typecheck parts of your code [1], but
you can also use it for things like data validation. [2]

Anyway, far from me the idea to turn Lua into Python. I just thought 
for once this proposal kind of fits the "mechanisms not policies" and
would be a good way to add type annotations to Lua *if* it gets some.
I will be perfectly happy if it never does as well, we can keep doing
that in other projects.

[1] https://typeguard.readthedocs.io/en/latest/
[2] https://docs.pydantic.dev/latest/

-- 
Pierre Chapuis