Adding Genericity to the Java Programming Language

Total Page:16

File Type:pdf, Size:1020Kb

Adding Genericity to the Java Programming Language Making the future safe for the past: Adding Genericity to the JavaTM Programming Language Gilad Bracha, Sun Microsystems, [email protected] Martin Odersky, University of South Australia, [email protected] David Stoutamire, Sun Microsystems, [email protected] Philip Wadler, Bell Labs, Lucent Technologies, [email protected]{labs.com Abstract This approach is exemplified by the Java program- ming language[GLS96]. Generics are represented by We present GJ, a design that extends the Java program- this idiom throughout the standard Java libraries, in- ming language with generic types and methods. These cluding vectors, hash tables, and enumerations. As the are both explained and implemented by translation into Java Development Kit (JDK) has evolved, generics have the unextended language. The translation closely mim- played an increasing role. JDK 1.1 introduced an ob- ics the way generics are emulated by programmers: it server pattern that depends on generics, as do the col- erases all type parameters, maps type variables to their lection classes introduced in JDK 1.2. Oberon also relies bounds, and inserts casts where needed. Some sub- on the generic idiom, and dynamically typed languages tleties of the translation are caused by the handling of such as Smalltalk [GR83] use this idiom implicitly. overriding. Nonetheless, generics may merit direct support. De- GJ increases expressiveness and safety: code utiliz- signing a language with direct support for subtyping ing generic libraries is no longer buried under a plethora and generics is straightforward. Examples include Mod- of casts, and the corresponding casts inserted by the ula 3, Ada 95, Eiffel, and Sather. Adding generics to translation are guaranteed to not fail. an existing language is almost routine. We proposed GJ is designed to be fully backwards compatible with adding generics to the Java programming language in the current Java language, which simplifies the tran- Pizza [OW97], and we know of four other proposals sition from non-generic to generic programming. In [AFM97, MBL97, TT98, CS98]. Clemens Szyperski particular, one can retrofit existing library classes with proposed adding generics to Oberon [RS97]. Strongtalk generic interfaces without changing their code. [BG93] layers a type system with generic types on top An implementation of GJ has been written in GJ, of Smalltalk. and is freely available on the web. The generic legacy problem However, few propos- 1 Introduction als tackle the generic legacy problem: when direct sup- port for generics is added to a language that supports Generic types are so important that even a language them via the generic idiom, what happens to legacy that lacks them may be designed to simulate them. code that exploits this idiom? Some object-oriented languages are designed to support Pizza is backward compatible with the Java pro- subtypes directly, and to support generics by the idiom gramming language, in that every legal program of the of replacing variable types by the top of the type hier- latter is also legal in the former. However, this compat- archy. For instance, a collection with elements of any ibility is of little help when it comes to generics. For type is represented by a collection with elements of type example, JDK 1.2 contains an extensive library of col- Object. lection classes based on the generic idiom. It is straight- forward to rewrite this library to use generics directly, To appear in the 13th Annual ACM SIGPLAN replacing the legacy type Collection by the parametric Conference on Object-Oriented Programming Sys- tems, Languages, and Applications (OOPSLA’98), type Collection<A>. However, in Pizza these two types Vancouver, BC, Canada, October, 1998. are incompatible, so one must rewrite all legacy code, or write adaptor code to convert between legacy and parametric types. Code bloat may result from refer- ences to both the legacy and parametric versions of Security One may contrast two styles of implement- the library. Note the problem is not merely with the ing generics, homogeneous and heterogeneous. The ho- size of legacy libraries (which may be small), but with mogeneous style, exemplified by the generic idiom, re- managing the upgrade from the legacy types to para- places occurrences of the type parameter by the type metric types (which can be a major headache if refer- Object. The heterogeneous style, exemplified by C++ ences to legacy types are dispersed over a large body and Ada, makes one copy of the class for each instantia- of code). If legacy libraries or code are available only tion of the the type parameter. The GJ and Pizza com- in binary rather than source, then these problems are pilers implement the homogeneous translation, while compounded. Agesen, Freund, and Mitchell [AFM97] propose having the class loader implement the heterogeneous transla- GJ Here we propose GJ, a superset of the Java pro- tion. Other proposals utilize a mixture of homogeneous gramming language that provides direct support for and heterogeneous techniques [CS98]. generics. GJ compiles into Java virtual machine (JVM) As observed by Agesen, Freund, and Mitchell, byte codes, and can be executed on any Java compli- the heterogeneous translation provides tighter security ant browser. In these respects GJ is like Pizza, but GJ guarantees than the homogeneous. For example, un- differs in that it also tackles the generic legacy problem. der the homogeneous translation a method expecting GJ contains a novel language feature, raw types, to a collection of secure channels may be passed a collec- capture the correspondence between generic and legacy tion of any kind of object, perhaps leading to a security types, and a retrofitting mechanism to allow generic breach. To minimize this problem, GJ always inserts types to be imposed on legacy code. A parametric type bridge methods when subclassing a generic class, so the Collection<A> may be passed wherever the correspond- user may ensure security simply by declaring suitable ing raw type Collection is expected. The raw type and specialized subclasses. parametric type have the same representation, so no The homogeneous translation also enjoys some ad- adaptor code is required. Further, retrofitting allows vantages over the heterogeneous. Surprisingly, with the one to attribute the existing collection class library with security model of the Java virtual machine, the hetero- parametric types, so one only requires one version of the geneous translation makes it impossible to form some library; an added plus is that new code will run in any sensible type instantiations. (This problem is entirely JDK 1.2 compliant browser against the built-in collec- obvious, but only in retrospect.) GJ and other lan- tion class library. Raw types and retrofitting apply even guages based on the homogeneous translation do not if libraries or code are available only as binary class files, suffer from this difficulty. and no source is available. Combined, these techniques greatly ease the task of upgrading from legacy code to Type inference While type systems for subtyping generics. and for generics are well understood, how to combine The semantics of GJ is given by a translation back the two remains a topic for active research. In particu- into the Java programming language. The translation lar, it can be difficult to infer instantiations for the type erases type parameters, replaces type variables by their arguments to generic methods. bounding type (typically Object), adds casts, and in- GJ uses a novel algorithm for this purpose, which serts bridge methods so that overriding works properly. combines two desirable (and at first blush contradic- The resulting program is pretty much what you would tory) properties: it is local, in that the type of an ex- write in the unextended language using the generic id- pression depends only on the types of its subexpres- iom. In pathological cases, the translation requires sions, and not on the context in which it occurs; and it bridge methods that can only be encoded directly in works for empty, in that inference produces best types JVM byte codes. Thus GJ extends the expressive power even for values like the empty list that have many pos- of the Java programming language, while remaining sible types. Further, the inference algorithm supports compatible with the JVM. subsumption, in that if an expression has a type, then GJ comes with a cast-iron guarantee: no cast in- it may be regarded as having any supertype of that serted by the compiler will ever fail. (Caveat: this guar- type. antee is void if the compiler generates an `unchecked' In contrast, the algorithm used in Pizza is non-local warning, which may occur if legacy and parametric code and does not support subsumption (although it does is mixed without benefit of retrofitting.) Furthermore, work for empty), while the algorithm used in Strongtalk since GJ compiles into the JVM, all safety and security [BG93] does not work for empty (although it is local and properties of the Java platform are preserved. (Reassur- supports subsumption), and algorithms for constraint- ance: this second guarantee holds even in the presence based type inference [AW93, EST95] are non-local (al- of unchecked warnings.) though they work for empty and support subsumption). Pizza uses a variant of the Hindley-Milner algorithm the relative strengths of parametric and virtual types [Mil78], which we regard as non-local since the type of appears elsewhere [BOW98]. It may be possible to a term may depend on its context through unification. merge virtual and parametric types [BOW98, TT98], but it is not clear whether the benefits of the merger Raw types and retrofitting Raw types serve two outweigh the increase in complexity. purposes in GJ: they support interfacing with legacy code, and they support writing code in those few sit- Status An implementation of GJ is freely available on uations (like the definition of an equality method) the web [GJ98a].
Recommended publications
  • Introduction Code Reuse
    The Sather Language: Efficient, Interactive, Object-Oriented Programming Stephen Omohundro Dr. Dobbs Journal Introduction Sather is an object oriented language which aims to be simple, efficient, interactive, safe, and non-proprietary. One way of placing it in the "space of languages" is to say that it aims to be as efficient as C, C++, or Fortran, as elegant and safe as Eiffel or CLU, and to support interactive programming and higher-order functions as well as Common Lisp, Scheme, or Smalltalk. Sather has parameterized classes, object-oriented dispatch, statically-checked strong typing, separate implementation and type inheritance, multiple inheritance, garbage collection, iteration abstraction, higher-order routines and iters, exception handling, constructors for arbitrary data structures, and assertions, preconditions, postconditions, and class invariants. This article describes the first few of these features. The development environment integrates an interpreter, a debugger, and a compiler. Sather programs can be compiled into portable C code and can efficiently link with C object files. Sather has a very unrestrictive license which allows its use in proprietary projects but encourages contribution to the public library. The original 0.2 version of the Sather compiler and tools was made available in June 1991. This article describes version 1.0. By the time the article appears, the combined 1.0 compiler/interpreter/debugger should be available on "ftp.icsi.berkeley.edu" and the newsgroup "comp.lang.sather" should be activated for discussion. Code Reuse The primary benefit promised by object-oriented languages is reuse of code. Sather programs consist of collections of modules called "classes" which encapsulate well-defined abstractions.
    [Show full text]
  • Generic Programming
    Generic Programming July 21, 1998 A Dagstuhl Seminar on the topic of Generic Programming was held April 27– May 1, 1998, with forty seven participants from ten countries. During the meeting there were thirty seven lectures, a panel session, and several problem sessions. The outcomes of the meeting include • A collection of abstracts of the lectures, made publicly available via this booklet and a web site at http://www-ca.informatik.uni-tuebingen.de/dagstuhl/gpdag.html. • Plans for a proceedings volume of papers submitted after the seminar that present (possibly extended) discussions of the topics covered in the lectures, problem sessions, and the panel session. • A list of generic programming projects and open problems, which will be maintained publicly on the World Wide Web at http://www-ca.informatik.uni-tuebingen.de/people/musser/gp/pop/index.html http://www.cs.rpi.edu/˜musser/gp/pop/index.html. 1 Contents 1 Motivation 3 2 Standards Panel 4 3 Lectures 4 3.1 Foundations and Methodology Comparisons ........ 4 Fundamentals of Generic Programming.................. 4 Jim Dehnert and Alex Stepanov Automatic Program Specialization by Partial Evaluation........ 4 Robert Gl¨uck Evaluating Generic Programming in Practice............... 6 Mehdi Jazayeri Polytypic Programming........................... 6 Johan Jeuring Recasting Algorithms As Objects: AnAlternativetoIterators . 7 Murali Sitaraman Using Genericity to Improve OO Designs................. 8 Karsten Weihe Inheritance, Genericity, and Class Hierarchies.............. 8 Wolf Zimmermann 3.2 Programming Methodology ................... 9 Hierarchical Iterators and Algorithms................... 9 Matt Austern Generic Programming in C++: Matrix Case Study........... 9 Krzysztof Czarnecki Generative Programming: Beyond Generic Programming........ 10 Ulrich Eisenecker Generic Programming Using Adaptive and Aspect-Oriented Programming .
    [Show full text]
  • Java for Scientific Computing, Pros and Cons
    Journal of Universal Computer Science, vol. 4, no. 1 (1998), 11-15 submitted: 25/9/97, accepted: 1/11/97, appeared: 28/1/98 Springer Pub. Co. Java for Scienti c Computing, Pros and Cons Jurgen Wol v. Gudenb erg Institut fur Informatik, Universitat Wurzburg wol @informatik.uni-wuerzburg.de Abstract: In this article we brie y discuss the advantages and disadvantages of the language Java for scienti c computing. We concentrate on Java's typ e system, investi- gate its supp ort for hierarchical and generic programming and then discuss the features of its oating-p oint arithmetic. Having found the weak p oints of the language we pro- p ose workarounds using Java itself as long as p ossible. 1 Typ e System Java distinguishes b etween primitive and reference typ es. Whereas this distinc- tion seems to b e very natural and helpful { so the primitives which comprise all standard numerical data typ es have the usual value semantics and expression concept, and the reference semantics of the others allows to avoid p ointers at all{ it also causes some problems. For the reference typ es, i.e. arrays, classes and interfaces no op erators are available or may b e de ned and expressions can only b e built by metho d calls. Several variables may simultaneously denote the same ob ject. This is certainly strange in a numerical setting, but not to avoid, since classes have to b e used to intro duce higher data typ es. On the other hand, the simple hierarchy of classes with the ro ot Object clearly b elongs to the advantages of the language.
    [Show full text]
  • CLOS, Eiffel, and Sather: a Comparison
    CLOS, Eiffel, and Sather: A Comparison Heinz W. Schmidt-, Stephen M. Omohundrot " September, 1991 li ____________T_R_._91_-0_47____________~ INTERNATIONAL COMPUTER SCIENCE INSTITUTE 1947 Center Street, Suite 600 Berkeley, California 94704-1105 CLOS, Eiffel, and Sather: A Comparison Heinz W. Schmidt-, Stephen M. Omohundrot September, 1991 Abstract The Common Lisp Object System defines a powerful and flexible type system that builds on more than fifteen years of experience with object-oriented programming. Most current implementations include a comfortable suite of Lisp support tools in­ cluding an Emacs Lisp editor, an interpreter, an incremental compiler, a debugger, and an inspector that together promote rapid prototyping and design. What else might one want from a system? We argue that static typing yields earlier error detec­ tion, greater robustness, and higher efficiency and that greater simplicity and more orthogonality in the language constructs leads to a shorter learning curve and more in­ tuitive programming. These elements can be found in Eiffel and a new object-oriented language, Sather, that we are developing at leS!. Language simplicity and static typ­ ing are not for free,·though. Programmers have to pay with loss of polymorphism and flexibility in prototyping. We give a short comparison of CLOS, Eiffel and Sather, addressing both language and environment issues. The different approaches taken by the languages described in this paper have evolved to fulfill different needs. While we have only touched on the essential differ­ ences, we hope that this discussion will be helpful in understanding the advantages and disadvantages of each language. -ICSI, on leave from: Inst. f. Systemtechnik, GMD, Germany tICSI 1 Introduction Common Lisp [25] was developed to consolidate the best ideas from a long line of Lisp systems and has become an important standard.
    [Show full text]
  • Iterable Abstract Pattern Matching for Java
    JMatch: Iterable Abstract Pattern Matching for Java Jed Liu and Andrew C. Myers Computer Science Department Cornell University, Ithaca, New York Abstract. The JMatch language extends Java with iterable abstract pattern match- ing, pattern matching that is compatible with the data abstraction features of Java and makes iteration abstractions convenient. JMatch has ML-style deep pattern matching, but patterns can be abstract; they are not tied to algebraic data con- structors. A single JMatch method may be used in several modes; modes may share a single implementation as a boolean formula. Modal abstraction simplifies specification and implementation of abstract data types. This paper describes the JMatch language and its implementation. 1 Introduction Object-oriented languages have become a dominant programming paradigm, yet they still lack features considered useful in other languages. Functional languages offer expressive pattern matching. Logic programming languages provide powerful mech- anisms for iteration and backtracking. However, these useful features interact poorly with the data abstraction mechanisms central to object-oriented languages. Thus, ex- pressing some computations is awkward in object-oriented languages. In this paper we present the design and implementation of JMatch, a new object- oriented language that extends Java [GJS96] with support for iterable abstract pattern matching—a mechanism for pattern matching that is compatible with the data abstrac- tion features of Java and that makes iteration abstractions more convenient.
    [Show full text]
  • Programming Paradigms
    PROGRAMMING PARADIGMS SNS COLLEGE OF TECHNOLOGY (An Autonomous Institution) COIMBATORE – 35 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (UG & PG) Third Year Computer Science and Engineering, 4th Semester QUESTION BANK UNIVERSITY QUESTIONS Subject Code & Name: 16CS206 PROGRAMMING PARADIGMS UNIT-IV PART – A 1. What is an exception? .(DEC 2011-2m) An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. 2. What is error? .(DEC 2011-2m) An Error indicates that a non-recoverable condition has occurred that should not be caught. Error, a subclass of Throwable, is intended for drastic problems, such as OutOfMemoryError, which would be reported by the JVM itself. 3. Which is superclass of Exception? .(DEC 2011-2m) "Throwable", the parent class of all exception related classes. 4. What are the advantages of using exception handling? .(DEC 2012-2m) Exception handling provides the following advantages over "traditional" error management techniques: Separating Error Handling Code from "Regular" Code. Propagating Errors Up the Call Stack. Grouping Error Types and Error Differentiation. 5. What are the types of Exceptions in Java .(DEC 2012-2m) There are two types of exceptions in Java, unchecked exceptions and checked exceptions. Checked exceptions: A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Each method must either SNSCT – Department of Compute Science and Engineering Page 1 PROGRAMMING PARADIGMS handle all checked exceptions by supplying a catch clause or list each unhandled checked exception as a thrown exception. Unchecked exceptions: All Exceptions that extend the RuntimeException class are unchecked exceptions.
    [Show full text]
  • Static Reflection
    N3996- Static reflection Document number: N3996 Date: 2014-05-26 Project: Programming Language C++, SG7, Reflection Reply-to: Mat´uˇsChochl´ık([email protected]) Static reflection How to read this document The first two sections are devoted to the introduction to reflection and reflective programming, they contain some motivational examples and some experiences with usage of a library-based reflection utility. These can be skipped if you are knowledgeable about reflection. Section3 contains the rationale for the design decisions. The most important part is the technical specification in section4, the impact on the standard is discussed in section5, the issues that need to be resolved are listed in section7, and section6 mentions some implementation hints. Contents 1. Introduction4 2. Motivation and Scope6 2.1. Usefullness of reflection............................6 2.2. Motivational examples.............................7 2.2.1. Factory generator............................7 3. Design Decisions 11 3.1. Desired features................................. 11 3.2. Layered approach and extensibility...................... 11 3.2.1. Basic metaobjects........................... 12 3.2.2. Mirror.................................. 12 3.2.3. Puddle.................................. 12 3.2.4. Rubber................................. 13 3.2.5. Lagoon................................. 13 3.3. Class generators................................ 14 3.4. Compile-time vs. Run-time reflection..................... 16 4. Technical Specifications 16 4.1. Metaobject Concepts.............................
    [Show full text]
  • Libraries for Generic Programming in Haskell
    Libraries for Generic Programming in Haskell Johan Jeuring, Sean Leather, Jos´ePedroMagalh˜aes, and Alexey Rodriguez Yakushev Universiteit Utrecht, The Netherlands Abstract. These lecture notes introduce libraries for datatype-generic program- ming in Haskell. We introduce three characteristic generic programming libraries: lightweight implementation of generics and dynamics, extensible and modular generics for the masses, and scrap your boilerplate. We show how to use them to use and write generic programs. In the case studies for the different libraries we introduce generic components of a medium-sized application which assists a student in solving mathematical exercises. 1 Introduction In the development of software, structuring data plays an important role. Many pro- gramming methods and software development tools center around creating a datatype (or XML schema, UML model, class, grammar, etc.). Once the structure of the data has been designed, a software developer adds functionality to the datatypes. There is always some functionality that is specific for a datatype, and part of the reason why the datatype has been designed in the first place. Other functionality is similar or even the same on many datatypes, following common programming patterns. Examples of such patterns are: – in a possibly large value of a complicated datatype (for example for representing the structure of a company), applying a given action at all occurrences of a par- ticular constructor (e.g., adding or updating zip codes at all occurrences of street addresses) while leaving the rest of the value unchanged; – serializing a value of a datatype, or comparing two values of a datatype for equality, functionality that depends only on the structure of the datatype; – adapting data access functions after a datatype has changed, something that often involves modifying large amounts of existing code.
    [Show full text]
  • Generic Programming Sean Parent | Principal Scientist “You Cannot Fully Grasp Mathematics Until You Understand Its Historical Context.” – Alex Stepanov
    Generic Programming Sean Parent | Principal Scientist “You cannot fully grasp mathematics until you understand its historical context.” – Alex Stepanov © 2018 Adobe. All Rights Reserved. 2 1988 © 2018 Adobe. All Rights Reserved. 3 © 2018 Adobe. All Rights Reserved. 4 © 2018 Adobe. All Rights Reserved. 4 © 2018 Adobe. All Rights Reserved. 4 “By generic programming we mean the definition of algorithms and data structures at an abstract or generic level, thereby accomplishing many related programming tasks simultaneously. The central notion is that of generic algorithms, which are parameterized procedural schemata that are completely independent of the underlying data representation and are derived from concrete, efficient algorithms.” © 2018 Adobe. All Rights Reserved. 5 “By generic programming we mean the definition of algorithms and data structures at an abstract or generic level, thereby accomplishing many related programming tasks simultaneously. The central notion is that of generic algorithms, which are parameterized procedural schemata that are completely independent of the underlying data representation and are derived from concrete, efficient algorithms.” © 2018 Adobe. All Rights Reserved. 6 “By generic programming we mean the definition of algorithms and data structures at an abstract or generic level, thereby accomplishing many related programming tasks simultaneously. The central notion is that of generic algorithms, which are parameterized procedural schemata that are completely independent of the underlying data representation and are derived from concrete, efficient algorithms.” © 2018 Adobe. All Rights Reserved. 7 “By generic programming we mean the definition of algorithms and data structures at an abstract or generic level, thereby accomplishing many related programming tasks simultaneously. The central notion is that of generic algorithms, which are parameterized procedural schemata that are completely independent of the underlying data representation and are derived from concrete, efficient algorithms.” © 2018 Adobe.
    [Show full text]
  • Concepts in Programming Languages
    Concepts in Programming Languages Alan Mycrofta Computer Laboratory University of Cambridge 2014–2015 (Easter Term) http://www.cl.cam.ac.uk/teaching/1415/ConceptsPL/ aNotes largely due to Marcelo Fiore—but errors are my responsibility. 1 Practicalities Course web page: www.cl.cam.ac.uk/teaching/1415/ConceptsPL/ with lecture slides, exercise sheet, and reading material. One exam question. 2 Main books J. C. Mitchell. Concepts in programming languages. Cambridge University Press, 2003. T.W. Pratt and M. V.Zelkowitz. Programming Languages: Design and implementation (3RD EDITION). Prentice Hall, 1999. ⋆ M. L. Scott. Programming language pragmatics (2ND EDITION). Elsevier, 2006. R. Harper. Practical Foundations for Programming Languages. Cambridge University Press, 2013. 3 Context : so many programming languages Peter J. Landin: “The Next 700 Programming Languages”, CACM >>>>1966<<<<. Some programming-language ‘family trees’ (too big for slide): http://www.oreilly.com/go/languageposter http://www.levenez.com/lang/ http://rigaux.org/language-study/diagram.html http://www.rackspace.com/blog/ infographic-evolution-of-computer-languages/ Plan of this course: pick out interesting programming- language concepts and major evolutionary trends. 4 Topics I. Introduction and motivation. II. The first procedural language: FORTRAN (1954–58). III. The first declarative language: LISP (1958–62). IV. Block-structured procedural languages: Algol (1958–68), Pascal (1970). V. Object-oriented languages — Concepts and origins: Simula (1964–67), Smalltalk (1971–80). VI. Languages for concurrency and parallelism. VII. Types in programming languages: ML (1973–1978). VIII. Data abstraction and modularity: SML Modules (1984–97). IX. A modern language design: Scala (2007) X. Miscellaneous concepts 5 Topic I Introduction and motivation References: g g Chapter 1 of Concepts in programming languages by J.
    [Show full text]
  • Generic Programming in OCAML
    Generic Programming in OCAML Florent Balestrieri Michel Mauny ENSTA-ParisTech, Université Paris-Saclay Inria Paris [email protected] [email protected] We present a library for generic programming in OCAML, adapting some techniques borrowed from other functional languages. The library makes use of three recent additions to OCAML: generalised abstract datatypes are essential to reflect types, extensible variants allow this reflection to be open for new additions, and extension points provide syntactic sugar and generate boiler plate code that simplify the use of the library. The building blocks of the library can be used to support many approachesto generic programmingthrough the concept of view. Generic traversals are implemented on top of the library and provide powerful combinators to write concise definitions of recursive functions over complex tree types. Our case study is a type-safe deserialisation function that respects type abstraction. 1 Introduction Typed functional programming languages come with rich type systems guaranteeing strong safety prop- erties for the programs. However, the restrictions imposed by types, necessary to banish wrong programs, may prevent us from generalizing over some particular programming patterns, thus leading to boilerplate code and duplicated logic. Generic programming allows us to recover the loss of flexibility by adding an extra expressive layer to the language. The purpose of this article is to describe the user interface and explain the implementation of a generic programming library1 for the language OCAML. We illustrate its usefulness with an implementation of a type-safe deserialisation function. 1.1 A Motivating Example Algebraic datatypes are very suitable for capturing structured data, in particular trees.
    [Show full text]
  • Object-Oriented and Concurrent Program Design Issues in Ada 95
    Object-Oriented and Concurrent Program Design Issues in Ada 95 Stephen H. Kaisler Michael B. Feldman Director, Systems Architecture Professor of Engineering and Applied Science Office of the Sergeant at Arms Dept. of Electrical Engineering and Computer Science United States Senate George Washington University Washington, DC 20510 Washington, DC 20052 202-224-2582 202-994-6083 [email protected] [email protected] 1. ABSTRACT Kaisler [4] identified several design issues that arose 2. INTRODUCTION from developing a process for transforming object- oriented programs written in Ada 95 or other object- Kaisler [4] described research leading to a methodology oriented programming languages to process-oriented for converting object-oriented programs to process- programs written in Ada 95. These issues limit - in the oriented programs and, thereby, making the concurrency authors' opinion - the flexibility of Ada 95 in writing implicit in object-oriented programs explicit. This concurrent programs. These problems arise from research was motivated by the fact that writing specific decisions made by the Ada 95 designers. This concurrent programs is difficult to do - no general paper addresses three of these issues: circular methodology exists - and by our recognition of the references are invalid in packages, lack of a similarity between object-oriented and process-oriented subclassing mechanism for protected types, and an programs. inability to internally invoke access statements from within a task body. Our goal is to raise the Ada 95 We believed that object-oriented programs, which exhibit community's awareness concerning these design issues a potential for concurrency, could be converted to and provide some suggestions for correcting these process-oriented programs, thereby making the problems for a future revision of the Ada concurrency explicit.
    [Show full text]