MOOL: an Object-Oriented Programming Language with Generics and Modules

Total Page:16

File Type:pdf, Size:1020Kb

MOOL: an Object-Oriented Programming Language with Generics and Modules MOOL: an Object-Oriented Programming Language with Generics and Modules. by María Lucía Barrón Estrada Maestro en Ciencias, en Ciencias Computacionales Instituto Tecnológico de Toluca México Licenciado en Informática Instituto Tecnológico de Culiacán México A dissertation submitted to Florida Institute of Technology in partial fulfillment of the requirements for the degree of Doctor of Philosophy in Computer Science Melbourne, Florida May, 2004 © Copyright 2004 María Lucía Barrón Estrada All Rights Reserved The author grants permission to make single copies ________________________ We the undersigned committee hereby recommend that the attached document be accepted as fulfilling in part the requirements for the degree of Doctor of Philosophy in Computer Science “MOOL: an Object-Oriented Programming Language with Generics and Modules,” a dissertation by María Lucía Barrón Estrada _________________________________ Ryan Stansifer, Ph.D. Associate Professor, Computer Sciences Dissertation Advisor _________________________________ Phil Bernhard, Ph.D. Associate Professor, Computer Sciences _________________________________ Pat Bond, Ph.D. Associate Professor, Computer Sciences _________________________________ Dennis E. Jackson, Ph.D. Associate Professor, _________________________________ William Shoaf, Ph.D. Associate Professor and Department Head, Computer Sciences Abstract Title: MOOL: an Object-Oriented Programming Language with Generics and Modules. Author: María Lucía Barrón Estrada Major Advisor: Ryan Stansifer, Ph.D. Modern object-oriented languages like Java and C# do not support parametric polymorphism and do not have a traditional module system to allow the development of large systems. They overload the class mechanism with several tasks and they use packages and namespaces to organize clusters of classes providing weak control for accessing members. Other languages that support generic programming and objects do not have a simple object model to support object-oriented features. In this thesis the language MOOL is presented. MOOL is a class-based object-oriented language that supports modular programming and genericity. The main goal in the design of MOOL was simplicity rather than efficiency. MOOL contains separated mechanisms for different concepts like classes and modules, which are unified in other languages. MOOL is not a pure object-oriented language where everything is an object. Non-object features like functions and modules are part of the language to enhance expressivity, to structure programs and to support code reuse. iii Table of Contents Keywords ............................................................................................................viii List of Figures....................................................................................................... ix List of Tables ....................................................................................................... xii Acknowledgement ..............................................................................................xiii Dedication ........................................................................................................... xiv Chapter 1. Introduction...................................................................................... 1 1.1. Problem description ................................................................................. 3 1.2. Road map ................................................................................................. 4 Chapter 2. Modules ............................................................................................. 6 2.1. Concepts................................................................................................... 7 2.2. Modularity goals ...................................................................................... 9 2.3. Kinds of modules ................................................................................... 11 2.3.1. Modules and interfaces.............................................................. 12 2.3.2. Libraries..................................................................................... 13 2.3.3. Shared data areas ....................................................................... 13 2.3.4. Generic modules........................................................................ 14 2.3.5. Parametric generic modules ...................................................... 15 2.4. Examples in some programming languages........................................... 17 2.4.1. Ada packages............................................................................. 18 2.4.2. Modula-3 modules..................................................................... 18 2.4.3. SML structures, signatures, and functors .................................. 20 2.4.4. Objective Caml.......................................................................... 22 2.4.5. Java packages ............................................................................ 23 2.4.6. C# namespaces and assemblies ................................................. 26 2.4.7. Dylan ......................................................................................... 27 Chapter 3. Object-Oriented Concepts............................................................. 29 3.1. Classification of object-oriented languages ........................................... 30 3.1.1. Passive languages ...................................................................... 30 3.1.2. Active languages ....................................................................... 31 3.1.3. Multimethod languages ............................................................. 33 3.2. Abstract data types and objects.............................................................. 36 3.3. Dynamic dispatch................................................................................... 37 iv 3.3.1. Single dispatch........................................................................... 38 3.3.2. Multiple dispatch....................................................................... 40 3.4. The special variables this and super ...................................................... 42 3.5. Inheritance.............................................................................................. 42 3.5.1. Single inheritance ...................................................................... 43 3.5.2. Multiple inheritance................................................................... 45 3.5.3. Mixin inheritance....................................................................... 47 3.5.4. Interface inheritance .................................................................. 49 3.6. Polymorphism ........................................................................................ 51 3.7. Types and Subtypes ............................................................................... 53 3.8. Some other concepts .............................................................................. 57 3.8.1. Type equivalency....................................................................... 57 3.8.2. Typechecking ............................................................................ 57 Chapter 4. Generics........................................................................................... 59 4.1. Parametric polymorphism ...................................................................... 60 4.2. Kinds of genericity................................................................................. 61 4.2.1. Unconstrained genericity........................................................... 62 4.2.2. Constrained genericity............................................................... 63 4.2.2.1. Simply bounded genericity ............................................... 64 4.2.2.2. Recursively bounded genericity........................................ 67 4.3. Translation.............................................................................................. 70 4.3.1. Homogeneous ............................................................................ 71 4.3.2. Heterogeneous ........................................................................... 73 4.3.3. Hybrid........................................................................................ 75 4.4. Examples of generics in some PL.......................................................... 77 4.4.1. Templates in C++ ...................................................................... 77 4.4.2. Parameterized classes in Pizza .................................................. 79 4.4.3. Virtual binding in BETA........................................................... 80 4.4.4. Class substitution in BOPL ....................................................... 82 Chapter 5. Analysis and Goals......................................................................... 84 5.1. Core features .......................................................................................... 85 5.2. Classes or objects? ................................................................................. 86 5.3. Type annotations and typechecking....................................................... 88 5.4. Subtypes ................................................................................................. 89 5.5. Inheritance.............................................................................................. 93 5.6. Bindings ................................................................................................
Recommended publications
  • Proof-Carrying Authentication∗
    Proof-Carrying Authentication∗ Andrew W. Appel and Edward W. Felten Secure Internet Programming Laboratory Department of Computer Science Princeton University Princeton, NJ 08544 USA August 9, 1999 Abstract Statements in these frameworks are represented as data structures that are often digitally signed We have designed and implemented a general to ensure their integrity. and powerful distributed authentication frame- work based on higher-order logic. Authenti- Several authentication frameworks exist; we cation frameworks — including Taos, SPKI, mention a few here as examples. The Taos SDSI, and X.509 — have been explained using operating system provided support for secure logic. We show that by starting with the logic, remote procedure call and data structures to we can implement these frameworks, all in the represent authority and identity [6]. X.509 [15] same concise and efficient system. Because our is a widely-used standard for expressing and us- logic has no decision procedure — although ing digital certificates. SPKI [4] and SDSI [14] proof checking is simple — users of the frame- (since merged under the joint name SPKI) work must submit proofs with their requests. were reactions to the perceived complexity of X.509; in both cases the ‘S’ stands for ‘simple.’ 1 Introduction PolicyMaker [3] is a language for expressing se- curity policies; it can be applied to distributed Distributed authentication frameworks allow security policies. Kerberos [12], unlike the other sharing of access to resources across adminis- frameworks, uses symmetric-key encryption to trative boundaries in a distributed system. The authenticate users. Each framework has a main abstractions they support are name-to- differerent semantics and offers a different kind key bindings, access control, and delegation.
    [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]
  • A Model of Inheritance for Declarative Visual Programming Languages
    An Abstract Of The Dissertation Of Rebecca Djang for the degree of Doctor of Philosophy in Computer Science presented on December 17, 1998. Title: Similarity Inheritance: A Model of Inheritance for Declarative Visual Programming Languages. Abstract approved: Margaret M. Burnett Declarative visual programming languages (VPLs), including spreadsheets, make up a large portion of both research and commercial VPLs. Spreadsheets in particular enjoy a wide audience, including end users. Unfortunately, spreadsheets and most other declarative VPLs still suffer from some of the problems that have been solved in other languages, such as ad-hoc (cut-and-paste) reuse of code which has been remedied in object-oriented languages, for example, through the code-reuse mechanism of inheritance. We believe spreadsheets and other declarative VPLs can benefit from the addition of an inheritance-like mechanism for fine-grained code reuse. This dissertation first examines the opportunities for supporting reuse inherent in declarative VPLs, and then introduces similarity inheritance and describes a prototype of this model in the research spreadsheet language Forms/3. Similarity inheritance is very flexible, allowing multiple granularities of code sharing and even mutual inheritance; it includes explicit representations of inherited code and all sharing relationships, and it subsumes the current spreadsheet mechanisms for formula propagation, providing a gradual migration from simple formula reuse to more sophisticated uses of inheritance among objects. Since the inheritance model separates inheritance from types, we investigate what notion of types is appropriate to support reuse of functions on different types (operation polymorphism). Because it is important to us that immediate feedback, which is characteristic of many VPLs, be preserved, including feedback with respect to type errors, we introduce a model of types suitable for static type inference in the presence of operation polymorphism with similarity inheritance.
    [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]
  • Unifying Theories of Objects
    Unifying Theories of Objects Michael Anthony Smith1;2 and Jeremy Gibbons1 1 Oxford University, UK. 2 Systems Assurance Group, QinetiQ, UK. [email protected] [email protected] Abstract. We present an approach to modelling Abadi{Cardelli-style object calculi as Unifying Theories of Programming (UTP) designs. Here we provide a core object calculus with an operational small-step evalua- tion rule semantics, and a corresponding UTP model with a denotational relational predicate semantics. For clarity, the UTP model is defined in terms of an operand stack, which is used to store the results of sub- programs. Models of a less operational nature are briefly discussed. The consistency of the UTP model is demonstrated by a structural induction proof over the operations of the core object calculus. Overall, our UTP model is intended to provide facilities for encoding both object-based and class-based languages. 1 Introduction Hoare and He's Unifying Theories of Programming (UTP) [6] can be used to formally define how results produced in one formal model can be translated as assumptions to another formal model. Essentially, programs are considered to be predicates that relate the values of their observable input and output variables (their alphabet). For example, the increment program x := x + 1 is typically defined by the relational predicate x 0 = x + 1, where predicate variables x and x 0 denote the input and output values of the program variable x. In general, the alphabet of a program P is denoted by αP; it is the disjoint union of P's input and output sets (inαP and outαP respectively), which in the case of the example is the set fx; x 0g.
    [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]
  • 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]
  • Comparative Study of Generic Programming Features in Object-Oriented Languages1
    Comparative Study of Generic Programming Features in Object-Oriented Languages1 Julia Belyakova [email protected] February 3rd 2017 NEU CCIS Programming Language Seminar 1Based on the papers [Belyakova 2016b; Belyakova 2016a] Generic Programming A term “Generic Programming” (GP) was coined in 1989 by Alexander Stepanov and David Musser Musser and Stepanov 1989. Idea Code is written in terms of abstract types and operations (parametric polymorphism). Purpose Writing highly reusable code. Julia Belyakova Generic Programming in OO Languages February 3, 2017 (PL Seminar) 2 / 45 Contents 1 Language Support for Generic Programming 2 Peculiarities of Language Support for GP in OO Languages 3 Language Extensions for GP in Object-Oriented Languages 4 Conclusion Julia Belyakova Generic Programming in OO Languages February 3, 2017 (PL Seminar) 3 / 45 Language Support for Generic Programming Unconstrained Generic Code 1 Language Support for Generic Programming Unconstrained Generic Code Constraints on Type Parameters 2 Peculiarities of Language Support for GP in OO Languages 3 Language Extensions for GP in Object-Oriented Languages 4 Conclusion Julia Belyakova Generic Programming in OO Languages February 3, 2017 (PL Seminar) 4 / 45 Count<T> can be instantiated with any type int[] ints = new int[]{ 3, 2, -8, 61, 12 }; var evCnt = Count(ints, x => x % 2 == 0);//T == int string[] strs = new string[]{ "hi", "bye", "hello", "stop" }; var evLenCnt = Count(strs, x => x.Length % 2 == 0);//T == string Language Support for Generic Programming Unconstrained
    [Show full text]
  • Admission Control for Independently-Authored Realtime Applications
    Admission Control for Independently-authored Realtime Applications by Robert Kroeger Athesis presented to the University of Waterloo in fulfilment of the thesis requirement for the degree of Doctor of Philosophy in Computer Science Waterloo, Ontario, Canada, 2004 c Robert Kroeger 2004 AUTHOR’S DECLARATION FOR ELECTRONIC SUBMISSION OF A THESIS I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required final revisions, as accepted by my examiners. I understand that my thesis may be made electronically available to the public. ii Abstract This thesis presents the LiquiMedia operating system architecture. LiquiMedia is specialized to schedule multimedia applications. Because they generate output for a human observer, multimedia applications such as video games, video conferencing and video players have both unique scheduling requirements and unique allowances: a multimedia stream must synchro- nize sub-streams generated for different sensory modalities within 20 milliseconds, it is not successfully segregated until it has existed for over 200 milliseconds and tolerates occasional scheduling failures. LiquiMedia is specialized around these requirements and allowances. First, LiquiMedia synchronizes multimedia tasks by invoking them from a shared realtime timer interrupt. Sec- ond, owing to multimedia’s tolerance of scheduling failures, LiquiMedia schedules tasks based on a probabilistic model of their running times. Third, LiquiMedia can infer per-task models while a user is segregating the streams that the tasks generate. These specializations provide novel capabilities: up to 2.5 times higher utilization than RMS scheduling, use of an atomic task primitive 9.5 times more efficient than preemptive threading, and most importantly, the ability to schedule arbitrary tasks to a known probability of realtime execution without a priori knowledge of their running times.
    [Show full text]