The Ergonomics of Type Checking (2016)
Can&#x27;t a compiler be created to traverse the AST, locate all operations performed on the variable and infer the narrowest type definition that allows for all of those operations, and then enforce at compile time?<p>Edit: example to further clarify what I meant (it&#x27;s a bit more than type inference at initial assignment)<p><pre><code>    var x = readUserInput(); &#x2F;&#x2F; narrow down: string, int, double
    x += y; &#x2F;&#x2F; if y is also a user input, no change
    x += 1; &#x2F;&#x2F; narrow down to int, double
    p = x % 2; &#x2F;&#x2F; narrow down to int</code></pre>