4 ms·
var in C# is only allowed for local variables, which means you can easily infer the type by analysing the assigment expression, which will always depend on know
by olavk 18y ago
var in C# is only allowed for local variables, which means you can easily infer the type by analysing the assigment expression, which will always depend on known types. For example method parameters are always explicitly typed.
Haskell style type inference is more tricky, since it also tries to infer the type of function signatures from the different contexts where the function is called. This can lead to circular type dependencies.
- crux_ 18y ago"Easily"? I suspect that since C#3 offers lambda expressions that you'd need to use something close to (although probably different from) full H-M inference... in fact, it seems like it may need to be nearly as complicated as Scala's type inference, which is saying something. =)
- olavk 18y agoI don't think you can assign a lambda expression to a var in C#.