←back to thread

218 points generichuman | 1 comments | | HN request time: 0.246s | source
Show context
kuruczgy ◴[] No.44001539[source]
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?)

replies(3): >>44001595 #>>44001876 #>>44005757 #
lolinder ◴[] No.44001876[source]
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 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.

replies(2): >>44002070 #>>44002505 #
kuruczgy ◴[] No.44002070[source]
> Your type system cannot be sound. It's going to have escape hatches and exceptions because that's how dynamic languages roll.

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

replies(1): >>44004710 #
1. lolinder ◴[] No.44004710[source]
Why, though? Completeness matters more than soundness in practice for this kind of language, which is a large part of what gave TypeScript its edge. The only people who complain about soundness seem to be those whose approach to TypeScript is one of theoretical interests rather than practical application.