Pitfalls of C# Generics and Their Solution Using Concepts

  • Belyakova J
  • Mikhalkovich S
N/ACitations
Citations of this article
5Readers
Mendeley users who have this article in their library.

Abstract

As was shown in earlier studies, in comparison with Haskell type classes and C++ concepts such mainstream object-oriented languages as C# and Java provide much limited mechanisms of generic programming based on F-bounded polymorphism. Main pitfalls of C# generics are carefully considered in this paper. A special attention is given to drawbacks of recursive constraints (F-constraints), ambiguous semantics of interfaces, lack of language support for multi-type constraints and retroactive interface implementation, and subtle problems of the Concept design pattern, which is widely used not only in C#, but in Java and Scala as well. To solve the problems of C# generics, extending C# language with concepts is proposed: as a new language construct, concepts are to be used as constraints on type parameters exclusively, with object-oriented interfaces being used as types. In contrast to basic C++ concepts, C# concepts may include subtype and supertype constraints, allow constraints aliasing and automatic generation of default models. The major differ-ence of the concepts design proposed is language support for multiple models. The latter feature is supported neither in C++ concepts, nor in Haskell type classes. In conclusion, a mechanism of implementation of concepts via translation to basic C# is outlined. The most important property of the translation is a possibility to recover a source code in extended language from a compiled module.

Cite

CITATION STYLE

APA

Belyakova, J., & Mikhalkovich, S. (2015). Pitfalls of C# Generics and Their Solution Using Concepts. Proceedings of the Institute for System Programming of the RAS, (3), 29–46. https://doi.org/10.15514/ispras-2015-27(3)-2

Register to see more suggestions

Mendeley helps you to discover research relevant for your work.

Already have an account?

Save time finding and organizing research with Mendeley

Sign up for free