Question: type erasure for features that require CLR changes? #4709
-
There are lot of features that are complicate to add to language because CLR does not support (at least is what I understood of what I have read) like type classes, higher kinded types, union intersection types, etc. My question is: could this kind of feature be implemented using type erasure? What are the tradeoffs? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
C# is designed to be close to CLR features. Type erasure shouldn't be considered. Moreover, the design of C# focuses on performance more and more now. |
Beta Was this translation helpful? Give feedback.
-
If you read up on the history of C# Generics, introduced in C# 2.0, you'll find that they were originally going to be implemented by type erasure (yes, really!). Fortunately, some of the smart folks from Microsoft Research were able to successfully lobby for generics to be deeply wired into the CLR, resulting in the superior implementation we enjoy today. Having the CLR fully aware of generics allows the JIT compiler to do some very smart things with optimization, increasing the speed of operation and, in some cases, reducing the memory footprint. One of the defining features of the C# language is the way that features are fully baked - they take the time to consider the implications of changes and put in the effort to ensure that everything works together in satisfactory ways. I don't believe type erasure is a good approach - it gives you a good fraction of the benefits, but at the cost of forever depriving you of the rest. For just one example, I don't believe LINQ would have been invented without CLR support for generics, and I suspect async/await would be the same. |
Beta Was this translation helpful? Give feedback.
If you read up on the history of C# Generics, introduced in C# 2.0, you'll find that they were originally going to be implemented by type erasure (yes, really!).
Fortunately, some of the smart folks from Microsoft Research were able to successfully lobby for generics to be deeply wired into the CLR, resulting in the superior implementation we enjoy today.
Having the CLR fully aware of generics allows the JIT compiler to do some very smart things with optimization, increasing the speed of operation and, in some cases, reducing the memory footprint.
One of the defining features of the C# language is the way that features are fully baked - they take the time to consider the implications of c…