3 ms·
> Flow types (for JavaScript) can be complied into run-time type-checks. Okay, so there are some, though flow is pretty obscure, and flow-runtime (which is the
by zohch 5y ago
> Flow types (for JavaScript) can be complied into run-time type-checks.
Okay, so there are some, though flow is pretty obscure, and flow-runtime (which is the part which does this AFAICT) is even more obscure. I don't think this is a popular feature.
> Properly statically typed languages do not need run-time checks because the compiled code is already proven to be valid by the type-checker.
If you want that, just enable strict mode for mypy.
And if you want to interface with code that is not stirctly typed, just use runtime type checks, which will inform the static type system:
foo: Any = untyped_code()
assert isinstance(foo, MyClass) # after this mypy will treat foo as instance of MyClass.
Same can be done with other types of checks also.
So if you want runtime type checking that informs the type system, you have it. I certainly don't want runtime checks for what the type system has already checked for me.
- breuleux 5y ago> If you want that, just enable strict mode for mypy. But I can't do that if I want to do gradual typing. If I type a function, but the type system cannot figure out what's going to call it, that's when I want it to perform a check: at the boundary. > I certainly don't want runtime checks for what the type system has already checked for me. The type system can remove the checks if it can prove that they always pass. My point is that if it cannot prove that they will pass, I want them at runtime.
- zohch 5y ago> But I can't do that if I want to do gradual typing. If I type a function, but the type system cannot figure out what's going to call it, that's when I want it to perform a check: at the boundary. Unless you start using # type: ignore - the only way to interface with untyped code will be to use asserts or other checks (if + throw), i.e. perform checks at the boundary.