Hacker News new | ask | show | jobs
by richard_todd 3338 days ago
It's not a compiler burden because it already has to determine the type of the right-hand side for typechecking purposes. So, the compiler actually does less work in the 'var' case, simply assigning the calculated type to the left-hand side rather than checking against a user-supplied type.
1 comments

Not really. Without type inference, there's always a pretty short path to the type: For "int x = y" you only have to check that the type of y is int. If you have type inference "int x = y" is a lot harder to validate, because y may have been defined like so "var y = z". So now you have to create some kind of list of variables and their types, start at the ones that are explicitly defined like "int a = b" or "c = 5" and then fill in the types of the rest as you find a reference to the ones you know.