Compiler-enforced type-restricted Type #1938
Replies: 4 comments
-
|
How would you propose that this be implemented? As of today the C# code |
Beta Was this translation helpful? Give feedback.
-
|
@HaloFour presumably it would still continue to do the same, but during the type checking stage after |
Beta Was this translation helpful? Give feedback.
-
|
It has to do more than validate a relationship, it has to cast the result to a different type. But the type returned from That all said, what would be the use cases for a feature like this? Java has this feature, where Java: Try<String> t1 = Try.success("hello");
Try<String> t2 = t1.recoverWith(IllegalArgumentException.class, exception -> "world");C# Try<string> t1 = Try.Success("hello");
Try<string> t2 = t1.RecoverWith<IllegalArgumentException>(exception => "world"); |
Beta Was this translation helpful? Give feedback.
-
|
@mqudsi |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There are a lot of open (and closed) issues for suggestions about taking C#'s static type checking to the next level or ideas on improving generic support. This is an RFC/suggestion that should enable a lot of the ideas without dramatically changing how the types are handled within the language itself by extending type-checking to literal
Typedeclarations, such as those viatypeof(...).The suggestion is to add a new type:
Which does nothing but hint to the compiler that it should mandate that any instances of this type should refer to types that implement/inherit from the named
ParentType(that's a lot of types!).Given the following code:
The following code would be legal:
but the following would generate a type error during compilation:
All presumably without breaking existing code or requiring any changes to the generated CLR.
Beta Was this translation helpful? Give feedback.
All reactions