
Parametric Polymorphism for Software Component Architectures Cosmin E. Oancea Stephen M. Watt Computer Science Department Computer Science Department The University of Western Ontario The University of Western Ontario London, Ontario, Canada London, Ontario, Canada [email protected] [email protected] ABSTRACT 1. INTRODUCTION Parametric polymorphism has become a common feature This paper examines what is required to have multi-lang- of mainstream programming languages, but software com- uage parameterized components interoperate and how to ac- ponent architectures have lagged behind and do not sup- cess existing generic libraries across language boundaries. port it. We examine the problem of providing paramet- We propose a common model for parametric polymorphism ric polymorphism with components combined from different that accommodates a representative range of different ob- programming languages. We have investigated how to re- ject semantics and binding times from various languages and solve different binding times and parametrization semantics use it to design a “generic” software component architecture in a range of representative languages and have identified extension that can be applied on top of most component ar- a common ground that can be suitably mapped to differ- chitectures in use today. ent language bindings. We present a generic component Software component architectures provide mechanisms for architecture extension that provides support for parameter- software modules to be developed independently, using dif- ized components and that can be easily adapted to work on ferent programming languages, and for these components to top of various software component architectures in use to- be combined in various configurations to construct appli- day (e.g., corba, dcom, jni). We have implemented and cations. To provide the richest environment, these architec- tested this architecture on top of corba. We also present tures have historically attempted to capture the intersection Generic Interface Definition Language (gidl), an extension of features of the programming languages for which they to corba-idl supporting generic types and we describe lan- have bindings. Common programming practice has evolved guage bindings for C++, Java and Aldor. We explain our a great deal, however, since the component architectures implementation of gidl, consisting of a gidl to idl com- in common use today were established. Notably, paramet- piler and tools for generating linkage code under the lan- ric polymorphism has evolved from a beautiful property of guage bindings. We demonstrate how this architecture can research-oriented programming languages to become a stan- be used to access C++’s stl and Aldor’s BasicMath libraries dard feature of languages used in mainstream applications. in a multi-language environment and discuss our mappings The concept of multi-language, multi-platform components in the context of automatic library interface generation. must similarly evolve if we wish our components to enjoy the benefits of parametric polymorphism. Categories and Subject Descriptors Parametric polymorphism is one mechanism by which pro- D.1.5 [Programming Techniques]: Object-oriented Pro- gramming languages may provide support for generic pro- gramming; D.2.2 [Software Engineering]: Modules and gramming. By associating all behavior of parameter values interfaces, Software libraries; D.2.11 [Software Engineer- with the types of the parameters, it becomes possible to ing]: Languages—interconnection; D.2.12 [Software En- write generic programs. These types can either be stated gineering]: Interoperability explicitly as parameters to a module, or inferred, depend- ing on the setting. Explicit parametric polymorphism has General Terms become more widely used, in practice, and has certain the- Languages, Design oretical benefits, including termination of type inference in some higher order languages [18]. Parametric polymorphism Keywords increases the flexibility, re-usability, and expressive power of Antiunification, Generics, Parametric Polymorphism, the programming environment, avoids the need for down- Software Component Architecture, Templates casting and allows a compiler to find more programming errors. There are quite a few popular programming lan- guages with support for parametric polymorphism, albeit with differing semantics. We review a few, to give an idea of Permission to make digital or hard copies of all or part of this work for the range a general facility must be able to map onto. Our personal or classroom use is granted without fee provided that copies are conclusion is that a mechanism to combine modules in differ- not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to ent programming languages must be able to accommodate republish, to post on servers or to redistribute to lists, requires prior specific both compile-time and run-time instantiation of modules permission and/or a fee. and both qualified and unqualified type variables. (Here, OOPSLA’05, October 16–20, 2005, San Diego, California, USA. and throughout the paper, we use the term qualified as a Copyright 2005 ACM 1-59593-031-0/05/0010 ...$5.00. synonym for bounded quantification [2].) 147 Our work was inspired by an early experiment [4], briefly 2. BACKGROUND AND MOTIVATION presented in Section 2, where two languages with differ- This section lays out the background and context for our ent parametric polymorphism semantics and different bind- work. We first explain the original motivation and the design ing time models were made to work together. The experi- point we desire to satisfy. We then lay out the context of the ment linked C++, with compile time template instantiation, work, summarizing the parametric polymorphism semantics and Aldor, with run time higher-order functions producing of a few languages to give an idea of the range a general dependent types. This experiment motivated the present, facility must be able to map on to. Finally, we briefly re- more general, approach. view several software component architectures in use today We have developed an extension to corba’s Interface Def- to understand how they can be extended with parametric inition Language (idl) to support parameterized interfaces. polymorphism. We have dubbed this extended specification language Generic IDL, or gidl for short. In this paper we present our im- 2.1 Motivation and Design Point plementation of , which consists of a to com- gidl gidl idl The initial motivation for our work arose building a link- piler and code generators implementing C++, Java and Aldor age between Aldor and C++ in the context of a European bindings. encapsulates a common model for generics gidl project for symbolic-numeric computation. The two main and provides efficient implementation under a wide spec- background items brought into the project were (1) a com- trum of requirements for specific semantics and binding times plex, heavily template-based C++ library, PoSSo, for the ex- of the supported languages. Our component architecture act solution of multivariate polynomial equations over var- extension does not assume a homogeneous environment. Its ious coefficient fields, and (2) an optimizing compiler for design, which constitutes in our view a novel application of a higher-order programming language, Aldor, used in com- the type erasure technique to implement generics in a het- puter algebra. One of the specific objectives of the project erogeneous environment, allows it to be easily adapted to was to allow Aldor programs to make use of the PoSSo li- work on top of most software component architectures in brary. From this very practical problem arose the interesting use today: is just our working study case. corba challenge to make two languages with very different binding To test the effectiveness of our model for generics, we time models and parametric polymorphism semantics work have investigated how to use gidl as a vehicle to access two together (C++ with compile-time template class instantia- generic libraries beyond their original language boundaries. tion and Aldor with run-time higher-order functions pro- The first library experiment implements a server incorporat- ducing dependent types). A detailed account of this work is ing part of the C++ Standard Template Library ( ) func- stl given elsewhere [4, 5]. This experiment established that we tionality. We have not re-written the stl: our implementa- could overcome the C++/ Aldor semantic gap and motivated tion uses the as a black box, wrapping it in a manner stl our search for a systematic solution for parametric polymor- that can easily be automated. We find that is perhaps gidl phism for components, encompassing more languages in a more suitable than C++ to express the “orthogonality” stl simpler way. semantics. Our specification is self-explanatory and self- Since the semantics of generics are different in various contained, in the sense that it does not need free language programming languages, we have been forced to identify a annotation to explain type safety constraints. The second common ground that can be suitably mapped to these lan- library experiment explores the high-level conceptual ideas guages efficiently. gidl supports mappings to Java, C++ and involved in mapping the semantics of the Aldor BasicMath Aldor, thus handling a wide spectrum of parametric poly- library to a specification. We see that Aldor’s func- gidl morphism and binding time semantics. We are not
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages20 Page
-
File Size-