A comparative study of language support for generic programming

Many modern programming languages support basic generic programming, sufficient to implement type-safe polymorphic containers. Some languages have moved beyond this basic support to a broader, more powerful interpretation of generic programming, and their extensions have proven valuable in practice. This paper reports on a comprehensive comparison of generics in six programming languages: C++, Standard ML, Haskell, Eiffel, Java (with its proposed generics extension), and Generic C. By implementing a substantial example in each of these languages, we identify eight language features that support this broader view of generic programming. We find these features are necessary to avoid awkward designs, poor maintainability, unnecessary run-time checks, and painfully verbose code. As languages increasingly support generics, it is important that language designers understand the features necessary to provide powerful generics and that their absence causes serious difficulties for programmers.

[1]  Bertrand Meyer,et al.  Type-safe covariance: Competent compilers can catch all catcalls , 2003 .

[2]  Todd L. Veldhuizen,et al.  Arrays in Blitz++ , 1998, ISCOPE.

[3]  Andrew C. Myers,et al.  Parameterized types for Java , 1997, POPL '97.

[4]  Jeremy G. Siek,et al.  Concept Checking: Binding Parametric Polymorphism in C++ , 2000 .

[5]  Bertrand Meyer Static typing , 1995, OOPSLA '95.

[6]  Gerald Baumgartner,et al.  Half & Half: Multiple Dispatch and Retroactive Abstraction for Java TM† , 2002 .

[7]  Gregor Kiczales,et al.  Aspect-oriented programming , 2001, ESEC/FSE-9.

[8]  Yannis Smaragdakis,et al.  Static interfaces in C , 2000 .

[9]  Wolfgang Weck,et al.  Compound types for Java , 1998, OOPSLA '98.

[10]  Jeremy G. Siek,et al.  The Matrix Template Library: A Generic Programming Approach to High Performance Numerical Linear Algebra , 1998, ISCOPE.

[11]  Jeremy G. Siek,et al.  The generic graph component library , 1999, OOPSLA '99.

[12]  Bertrand Meyer,et al.  Eiffel: The Language , 1991 .

[13]  Bjarne Stroustrup,et al.  The Design and Evolution of C , 1994 .

[14]  Ralf Hinze,et al.  Haskell 98 — A Non−strict‚ Purely Functional Language , 1999 .

[15]  Andrew Kennedy,et al.  Design and implementation of generics for the .NET Common language runtime , 2001, PLDI '01.

[16]  Roland Carl Backhouse,et al.  Generic Programming: An Introduction , 1998, Advanced Functional Programming.

[17]  Gerald Baumgartner,et al.  Safe Structural Conformance for Java , 2000, Comput. J..

[18]  Douglas C. Schmidt,et al.  External Polymorphism An Object Structural Pattern for Transparently Extending C++ Concrete Data Types , 1998 .

[19]  Michael J. Vilot,et al.  Standard template library , 1996 .

[20]  Ralf Hinze,et al.  Generic Haskell: Practice and Theory , 2003, Generic Programming.

[21]  Matthew H. Austern Generic programming and the STL - using and extending the C++ standard template library , 1999, Addison-Wesley professional computing series.

[22]  William R. Cook,et al.  A Proposal for Making Eiffel Type-Safe , 1989, Comput. J..

[23]  Jeremy G. Siek,et al.  The Boost Graph Library - User Guide and Reference Manual , 2001, C++ in-depth series.

[24]  Martin Odersky,et al.  Making the future safe for the past: adding genericity to the Java programming language , 1998, OOPSLA '98.

[25]  Alexander A. Stepanov,et al.  Generic Programming , 1988, ISSAC.

[26]  Simon Peyton Jones,et al.  Type classes: an exploration of the design space , 1997 .

[27]  Johan Jeuring,et al.  Polytypic Programming , 1996, Advanced Functional Programming.

[28]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[29]  T. Lindvall ON A ROUTING PROBLEM , 2004, Probability in the Engineering and Informational Sciences.

[30]  Bertrand Meyer The Start of an Eiffel Standard , 2002, J. Object Technol..

[31]  Shirley Dex,et al.  JR 旅客販売総合システム(マルス)における運用及び管理について , 1991 .

[32]  R. Prim Shortest connection networks and some generalizations , 1957 .

[33]  Edsger W. Dijkstra,et al.  A note on two problems in connexion with graphs , 1959, Numerische Mathematik.

[34]  William G. Griswold,et al.  An Overview of AspectJ , 2001, ECOOP.

[35]  Robert Cartwright,et al.  Compatible genericity with run-time types for the Java programming language , 1998, OOPSLA '98.

[36]  Mark P. Jones,et al.  Type Classes with Functional Dependencies , 2000, ESOP.

[37]  Matthew Harold Austern,et al.  Generic programming and the STL , 1998 .