Recently I've experimented with an implementation of the visitor pattern, where I've tried to enforce Accept & Visit methods with generic interfaces:
In Chapter 3 of The Rust Programming Language, the following code is used as an example for a kind of type inference that Rust cannot manage:
I don't understand why this code should pass type-checking:Since each component is bound to the same variable x, I would expect that the most general type for this expression to be (Maybe a, Maybe a). I get the same results if I use a where instead of a let. Am...
I was curious to see if the above snippet of code would compile and run successfully, and it does! However, I also wondered what would happen if T extends String was replaced with T extends String & AutoClosable; String does not implement AutoClosable, so I didn't expect this to run...
Background: the question came up in this answer (the first revision of the answer, to be exact). The code presented in this question is reduced to the bare minimum to explain the problem.
Consider the functionWhat is its type? Obviously I can just use :t f to find out, but if I need to deduce this manually, what's the best way to go about this?
C# cannot infer a type argument in this pretty obvious case:The JObject type clearly implements IEnumerable<KeyValuePair<string, JToken>>, but I get the following error: