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. 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 ................................................................................................