What is Vec?

It means “Rust compiler, infer what type goes into the Vec“. And it is indeed analogous to the unused variable in Python (and in Rust itself), in that it represents a placeholder for a type, like it can represent a placeholder for a variable name. You can find an explanation in The Rust Programming Language … Read more

How to call a named constructor from a generic function in Dart/Flutter

Dart does not support instantiating from a generic type parameter. It doesn’t matter if you want to use a named or default constructor (T() also does not work). There is probably a way to do that on the server, where dart:mirrors (reflection) is available (not tried myself yet), but not in Flutter or the browser. … Read more

How do closures infer their type based on the trait they’re required to implement?

It seems to be a glitch. The Rust-analyzer LSP is able to infer what the type is supposed to be, but for whatever reason the compiler can’t. From what I can tell, this code doesn’t compile on any version of Rust, and cannot be automatically fixed with cargo fix. Interestingly, the compiler does seem to … Read more

C# Adding two Generic Values

There is no generic constraint that allows you to enforce operator overload. You may take a look at the following library. Alternatively if you are using .NET 4.0 you could use the dynamic keyword: public static T Add<T>(T number1, T number2) { dynamic a = number1; dynamic b = number2; return a + b; } … Read more

Functions with generic parameter types

Overloading is typically the bugaboo of type-inferenced languages (at least when, like F#, the type system isn’t powerful enough to contain type-classes). There are a number of choices you have in F#: Use overloading on methods (members of a type), in which case overloading works much like as in other .Net languages (you can ad-hoc … Read more