Re:Why don't more languages offer flow typing?
by xg15 on Monday April 04, 2022 @06:39PM
(#30912907)
Yes, that's correct. In the GP example, c was const, so the type can be determined at compile time.
Re:Why don't more languages offer flow typing?
by simulate-me on Monday April 04, 2022 @07:55PM
(#30913520)
I was writing TypeScript, where const just means the variable is not reassigned. For instance this is valid:
const c: C = Math.random() < 0.5 ? { type: 'a' } : { type: 'b' }.
if (c.type === 'a') { /* c is of type A here */ }
This is dynamic typing, this code is checked at runtime, and it's leveraged statically.