Type Classes and Subtyping Two Different Approaches of Polymorphism

Total Page:16

File Type:pdf, Size:1020Kb

Type Classes and Subtyping Two Different Approaches of Polymorphism Type Classes and Subtyping Two different Approaches of Polymorphism Lars Hupel June 20, 2011 Abstract Traditionally, object oriented and functional programming languages have very few in common. While most of the former practise inheritance of classes, therefore introducing a concept of “subtyping”, the latter usually have algebraic data types without substitutability. However, Haskell’s type classes serve a similar purpose as (Java’s) inheritance: polymor- phism, a mechanism to allow functions to act differently depending on the type of values they act upon. This article will introduce these two seemingly contrary concepts and shows how to unify them. 1 Introduction Before talking about type classes and subtyping, we will first explore the mean- ing of polymorphism with respect to object-oriented programming languages. There are two main types of OOP languages, class-based and prototype-based, with JavaScript being the most famous of the few incarnations of the latter category. There may also be polymorphism in this category, but this kind is dif- ferent as it is mostly a consequence of the dynamic nature of these languages and therefore represents a different approach. Hence, we will restrict the following consideration to polymorphism in class-based, statically-typed OOP languages. Java For example, consider the object system of Java. Java defines classes as the main structure to organize data. If one class should inherit from another one, this has to be declared by using the extends keyword. Once extended, a fixed inheritance hierarchy is established, such that every time an instance of the superclass is expected, an instance of the subclass may be used instead. Java only allows to inherit from one class with Object being the head of the hierarchy. (The native types, e. g. int and float, exist independently. Values of those types are not objects and are thus treated differently.) It is however possible to implement syntactical interfaces which do not carry any method bodies. This restriction has been established, because it avoids the diamond problem known from other languages (as in C++, described below). Subclasses may (except for a couple of cases) override implementations of meth- ods, that is, supply a different method body for methods which already have a 1 body in one of the superclasses. Calls to methods are then dispatched dynam- ically, meaning that the lowermost (with respect to the inheritance hierarchy) defined body of this method is invoked. C++ One popular language allowing inheritance from more than one class is C++. The language has no distinction between interfaces and “regular” classes. Also, calls are statically dispatched, except when the virtual mod- ifier is present. Also, C++ has no head class of the hierarchy1. Suppose there is a hierarchy consisting of the four classes A, B, C and D with B and C inheriting from A and D inheriting from B and C. Furthermore, all classes except D implement a method f. When calling f on an instance of D, the compiler is unable to determine whether B::f or C::f should be invoked (the so called diamond problem) [4, 15, §15.2]. OCaml This functional language uses a different approach to subtyping, as this relation does not have to be declared explicitly. Classes are only used as primitive templates for objects, such that an object is typed by the public methods it exposes2. Whether two values are substitutable is decided based on the compatibility of the signature. Inheritance for classes only means that the methods of the superclass are copied into the subclass [1]. Inheritance vs. Subtyping We can conclude that inheritance and subtyping are two related, but separate issues. This distinction is clear for languages with structural subtyping (as OCaml) and not so clear for languages with nominal subtyping (as Java and C++). There are also languages with a mixture between both (as Scala). 2 Subtyping 2.1 Concepts Definition In general, subtyping means the substitutability of values of an supertype by values of a subtype. In that case, some sort of “hierarchy” is introduced which does not necessarily have to be a tree. It is clear though that it induces a relation S <: T, where S is a subtype of T. A good example for that is a hierarchy of number types, where Number is the supertype of e. g. Integer, Float and Complex. Every algorithm which takes a Number as an input is therefore able to take an Integer instead. There is a formalization of this model, called the Liskov substitution principle (LSP), as stated by Barbara Liskov and Jeanette Wing as following: 1There is a special pointer-to-void type, void*, though, classifying a pointer to a value of unknown type. 2In fact, a signature is written as < name : type ; .. > where the ellipsis stands for arbitrary methods. Every object exposing only the specified methods – regardless of its other methods – may be passed where this type is expected. 2 “Let φ(x) be a property provable about objects x of type T. Then φ(y) should be true for objects y of type S where S is a subtype of T.” [6, p. 1] The LSP is important in deciding whether a type should be modelled as a subtype of another type. For example, consider the two types Square and Rectangle. From a mathematical point of view, a square is clearly a rectangle with the additional property that all sides have the same length. However, if we set φ to “may be scaled independently horizontally and vertically”, the LSP would not hold for Square <: Rectangle, because φ is true for rectangles but not for squares. For the opposite direction assume φ0 is “can be described by only one length”. φ0 is true for squares but not for rectangles which leaves us with the conclusion that Rectangle <: Square does not hold either. Note that the set of properties which should be satisfied by a given hierarchy depends on the requirements. In a context where immutability is desired, it would be fine to define Square as a subtype of Rectangle, because φ is no longer a property of rectangles. Classes and inheritance The subtype relation does not imply anything about the actual implementation of two types S <: T. Speaking about Java, S and T denote interfaces without implementing classes involved. In contrast, the concept of a class entails an implementation which conforms to the interface. More generally speaking, an object is a collection of fields. Every field denotes an attribute (value, property) or a method (procedure, behaviour). In pure OOP languages, everything is an object, even “primitive” types which have a correspondence on hardware like floating point numbers or integers. As we are just regarding class-based languages, every object is an instance of a class where the class serves as a template and a mechanism to construct new instances. As seen earlier, inheritance and subtyping are different matters. In Java, a class is coupled with a type which makes this distinction a bit opaque. Subtyping, as defined by Liskov, works on a semantical level, whereas Java only requires a class to implement the methods from every used interface. For example, consider an interface for sorting values: interface Sort { /** * Sorts an array. * The input array is not modified. * @return an array with the same values as the * input but in ascending order */ int[] sort(int[] input); } Nothing prevents a class implementing Sort and ignoring the “contract” of sort, for instance by mutating the input array. With respect to behavioural subtyping, 3 such a “malicious” class would not be a subtype of Sort. Obviously, checking such a contract is a particularly hard task as it requires the definition of pre- and postconditions and a tool which checks the compliance at compile or run time. Such approaches have been made (e. g. [2]), but the vast majority simply uses Javadoc comments as shown above. Coming back to our example, modelling Square <: Rectangle. Assume both types are represented by classes. Then, Rectangle may have two fields for both lengths. If Square inherits from Rectangle, it also gets these fields although a square is defined by only one length. It is no problem for Square to keep both lengths synchronized, but such redundancies are generally undesired and should be taken into consideration when modelling class hierarchies. Variance A source of never ending joy (and confusion) are the consequences of variance with respect to both subtyping and generic types. Assume that A <: B and C <: D and the two function types τ1 = B -> C and τ2 = A -> D. Let φ1 be the property “may take any instance of A” and φ2 “returns an instance of D”. Then, of course φ2 holds for both τ1 and τ2, because all instances of C are also instances of D. φ1 trivially holds for τ2, but also for τ1 as the set of instances of A is a subset of the set of instances of B. Thus, we have shown that τ1 <: τ2 [17, p. 6]. These properties are important when the signature of a method in a subtype is different from the signature of the corresponding method in the supertype. The parameter types of a method are contravariant, whereas the return type is covariant [6, p. 10, 18, §2]. In conclusion, there are three possibilities of variance where a type appears in a particular position: covariant iff S <: T, S may be used instead of T, thus preserving the original order contravariant iff S <: T, T may be used instead of S, reversing the subtyping order invariant neither covariance or contravariance applies The concept of variance may be generalized, which immediately leads to generic programming. The variance of A :> B is just a special case, as most OOP languages allow classes to be parametrized on types.
Recommended publications
  • 1=Haskell =1=Making Our Own Types and Typeclasses
    Haskell Making Our Own Types and Typeclasses http://igm.univ-mlv.fr/~vialette/?section=teaching St´ephaneVialette LIGM, Universit´eParis-Est Marne-la-Vall´ee November 13, 2016 Making Our Own Types and Typeclasses Algebraic data types intro So far, we've run into a lot of data types: Bool, Int, Char, Maybe, etc. But how do we make our own? One way is to use the data keyword to define a type. Let's see how the Bool type is defined in the standard library. data Bool= False| True data means that we're defining a new data type. Making Our Own Types and Typeclasses Algebraic data types intro data Bool= False| True The part before the = denotes the type, which is Bool. The parts after the = are value constructors. They specify the different values that this type can have. The | is read as or. So we can read this as: the Bool type can have a value of True or False. Both the type name and the value constructors have to be capital cased. Making Our Own Types and Typeclasses Algebraic data types intro We can think of the Int type as being defined like this: data Int=-2147483648|-2147483647| ...|-1|0|1|2| ...| 2147483647 The first and last value constructors are the minimum and maximum possible values of Int. It's not actually defined like this, the ellipses are here because we omitted a heapload of numbers, so this is just for illustrative purposes. Shape let's think about how we would represent a shape in Haskell.
    [Show full text]
  • A Polymorphic Type System for Extensible Records and Variants
    A Polymorphic Typ e System for Extensible Records and Variants Benedict R. Gaster and Mark P. Jones Technical rep ort NOTTCS-TR-96-3, November 1996 Department of Computer Science, University of Nottingham, University Park, Nottingham NG7 2RD, England. fbrg,[email protected] Abstract b oard, and another indicating a mouse click at a par- ticular p oint on the screen: Records and variants provide exible ways to construct Event = Char + Point : datatyp es, but the restrictions imp osed by practical typ e systems can prevent them from b eing used in ex- These de nitions are adequate, but they are not par- ible ways. These limitations are often the result of con- ticularly easy to work with in practice. For example, it cerns ab out eciency or typ e inference, or of the di- is easy to confuse datatyp e comp onents when they are culty in providing accurate typ es for key op erations. accessed by their p osition within a pro duct or sum, and This pap er describ es a new typ e system that reme- programs written in this way can b e hard to maintain. dies these problems: it supp orts extensible records and To avoid these problems, many programming lan- variants, with a full complement of p olymorphic op era- guages allow the comp onents of pro ducts, and the al- tions on each; and it o ers an e ective type inference al- ternatives of sums, to b e identi ed using names drawn gorithm and a simple compilation metho d.
    [Show full text]
  • Assignment 6: Subtyping and Bidirectional Typing
    Assignment 6: Subtyping and Bidirectional Typing 15-312: Foundations of Programming Languages Joshua Dunfield ([email protected]) Out: Thursday, October 24, 2002 Due: Thursday, November 7 (11:59:59 pm) 100 points total + (up to) 20 points extra credit 1 Introduction In this assignment, you will implement a bidirectional typechecker for MinML with , , +, 1, 0, , , and subtyping with base types int and float. ! ∗ 8 9 Note: In the .sml files, most changes from Assignment 4 are indicated like this: (* new asst6 code: *) ... (* end asst6 code *) 2 New in this assignment Some things have become obsolete (and have either been removed or left • in a semi-supported state). Exceptions and continuations are no longer “officially” supported. One can now (and sometimes must!) write type annotations e : τ. The • abstract syntax constructor is called Anno. The lexer supports shell-style comments in .mml source files: any line • beginning with # is ignored. There are now two valid syntaxes for functions, the old syntax fun f (x:t1):t2 is e end • and a new syntax fun f(x) is e end. Note the lack of type anno- tations. The definition of the abstract syntax constructor Fun has been changed; its arguments are now just bindings for f and x and the body. It no longer takes two types. 1 The old syntax fun f(x:t1):t2 is e end is now just syntactic sugar, transformed by the parser into fun f(x) is e end : t1 -> t2. There are floating point numbers, written as in SML. There is a new set of • arithmetic operators +., -., *., ˜.
    [Show full text]
  • Java Secrets.Pdf
    Java Secrets by Elliotte Rusty Harold IDG Books, IDG Books Worldwide, Inc. ISBN: 0764580078 Pub Date: 05/01/97 Buy It Preface About the Author Part I—How Java Works Chapter 1—Introducing Java SECRETS A Little Knowledge Can Be a Dangerous Thing What’s in This Book? Part I: How Java Works Part II: The sun Classes Part III: Platform-Dependent Java Why Java Secrets? Broader applicability More power Inspiration Where Did the Secrets Come From? Where is the documentation? The source code The API documentation What Versions of Java Are Covered? Some Objections Java is supposed to be platform independent Why aren’t these things documented? FUD (fear, uncertainty, and doubt) How secret is this, anyway? Summary Chapter 2—Primitive Data Types Bytes in Memory Variables, Values, and Identifiers Place-Value Number Systems Binary notation Hexadecimal notation Octal notation Integers ints Long, short, and byte Floating-Point Numbers Representing floating-point numbers in binary code Special values Denormalized floating-point numbers CHAR ASCII ISO Latin-1 Unicode UTF8 Boolean Cross-Platform Issues Byte order Unsigned integers Integer widths Conversions and Casting Using a cast The mechanics of conversion Bit-Level Operators Some terminology Bitwise operators Bit shift operators Summary Chapter 2—Primitive Data Types Bytes in Memory Variables, Values, and Identifiers Place-Value Number Systems Binary notation Hexadecimal notation Octal notation Integers ints Long, short, and byte Floating-Point Numbers Representing floating-point numbers in binary code
    [Show full text]
  • Lecture Slides
    Outline Meta-Classes Guy Wiener Introduction AOP Classes Generation 1 Introduction Meta-Classes in Python Logging 2 Meta-Classes in Python Delegation Meta-Classes vs. Traditional OOP 3 Meta-Classes vs. Traditional OOP Outline Meta-Classes Guy Wiener Introduction AOP Classes Generation 1 Introduction Meta-Classes in Python Logging 2 Meta-Classes in Python Delegation Meta-Classes vs. Traditional OOP 3 Meta-Classes vs. Traditional OOP What is Meta-Programming? Meta-Classes Definition Guy Wiener Meta-Program A program that: Introduction AOP Classes One of its inputs is a program Generation (possibly itself) Meta-Classes in Python Its output is a program Logging Delegation Meta-Classes vs. Traditional OOP Meta-Programs Nowadays Meta-Classes Guy Wiener Introduction AOP Classes Generation Compilers Meta-Classes in Python Code Generators Logging Delegation Model-Driven Development Meta-Classes vs. Traditional Templates OOP Syntactic macros (Lisp-like) Meta-Classes The Problem With Static Programming Meta-Classes Guy Wiener Introduction AOP Classes Generation Meta-Classes How to share features between classes and class hierarchies? in Python Logging Share static attributes Delegation Meta-Classes Force classes to adhere to the same protocol vs. Traditional OOP Share code between similar methods Meta-Classes Meta-Classes Guy Wiener Introduction AOP Classes Definition Generation Meta-Classes in Python Meta-Class A class that creates classes Logging Delegation Objects that are instances of the same class Meta-Classes share the same behavior vs. Traditional OOP Classes that are instances of the same meta-class share the same behavior Meta-Classes Meta-Classes Guy Wiener Introduction AOP Classes Definition Generation Meta-Classes in Python Meta-Class A class that creates classes Logging Delegation Objects that are instances of the same class Meta-Classes share the same behavior vs.
    [Show full text]
  • (901133) Instructor: Eng
    home Al-Albayt University Computer Science Department C++ Programming 1 (901133) Instructor: Eng. Rami Jaradat [email protected] 1 home Subjects 1. Introduction to C++ Programming 2. Control Structures 3. Functions 4. Arrays 5. Pointers 6. Strings 2 home 1 - Introduction to C++ Programming 3 home What is computer? • Computers are programmable devices capable of performing computations and making logical decisions. • Computers can store, retrieve, and process data according to a list of instructions • Hardware is the physical part of the compute: keyboard, screen, mouse, disks, memory, and processing units • Software is a collection of computer programs, procedures and documentation that perform some tasks on a computer system 4 home Computer Logical Units • Input unit – obtains information (data) from input devices • Output unit – outputs information to output device or to control other devices. • Memory unit – Rapid access, low capacity, stores information • Secondary storage unit – cheap, long-term, high-capacity storage, stores inactive programs • Arithmetic and logic unit (ALU) – performs arithmetic calculations and logic decisions • Central processing unit (CPU): – supervises and coordinates the other sections of the computer 5 home Computer language • Machine languages: machine dependent, it consists of strings of numbers giving machine specific instructions: +1300042774 +1400593419 +1200274027 • Assembly languages: English-like abbreviations representing elementary operations, assemblers convert assembly language to machine
    [Show full text]
  • Haskell-Style Type Classes with Isabelle/Isar
    Isar ∀ Isabelle= α λ β → Haskell-style type classes with Isabelle/Isar Florian Haftmann 20 February 2021 Abstract This tutorial introduces Isar type classes, which are a convenient mech- anism for organizing specifications. Essentially, they combine an op- erational aspect (in the manner of Haskell) with a logical aspect, both managed uniformly. 1 INTRODUCTION 1 1 Introduction Type classes were introduced by Wadler and Blott [8] into the Haskell lan- guage to allow for a reasonable implementation of overloading1. As a canon- ical example, a polymorphic equality function eq :: α ) α ) bool which is overloaded on different types for α, which is achieved by splitting introduc- tion of the eq function from its overloaded definitions by means of class and instance declarations: 2 class eq where eq :: α ) α ) bool instance nat :: eq where eq 0 0 = True eq 0 - = False eq - 0 = False eq (Suc n)(Suc m) = eq n m instance (α::eq; β::eq) pair :: eq where eq (x1; y1) (x2; y2) = eq x1 x2 ^ eq y1 y2 class ord extends eq where less-eq :: α ) α ) bool less :: α ) α ) bool Type variables are annotated with (finitely many) classes; these annotations are assertions that a particular polymorphic type provides definitions for overloaded functions. Indeed, type classes not only allow for simple overloading but form a generic calculus, an instance of order-sorted algebra [5, 6, 10]. From a software engineering point of view, type classes roughly correspond to interfaces in object-oriented languages like Java; so, it is naturally desirable that type classes do not only provide functions (class parameters) but also state specifications implementations must obey.
    [Show full text]
  • Explicitly Implicifying Explicit Constructors
    Explicitly Implicifying explicit Constructors Document number: P1163R0 Date: 2018-08-31 Project: Programming Language C++, Library Working Group Reply-to: Nevin “☺” Liber, [email protected] or [email protected] Table of Contents Revision History ................................................................................................................ 3 P11630R0 .................................................................................................................................... 3 Introduction ....................................................................................................................... 4 Motivation and Scope ....................................................................................................... 5 Impact On the Standard ................................................................................................... 6 Policy .................................................................................................................................. 7 Design Decisions ................................................................................................................ 8 Technical Specifications ................................................................................................... 9 [template.bitset]........................................................................................................................ 10 [bitset.cons] ..............................................................................................................................
    [Show full text]
  • OMG Meta Object Facility (MOF) Core Specification
    Date : October 2019 OMG Meta Object Facility (MOF) Core Specification Version 2.5.1 OMG Document Number: formal/2019-10-01 Standard document URL: https://www.omg.org/spec/MOF/2.5.1 Normative Machine-Readable Files: https://www.omg.org/spec/MOF/20131001/MOF.xmi Informative Machine-Readable Files: https://www.omg.org/spec/MOF/20131001/CMOFConstraints.ocl https://www.omg.org/spec/MOF/20131001/EMOFConstraints.ocl Copyright © 2003, Adaptive Copyright © 2003, Ceira Technologies, Inc. Copyright © 2003, Compuware Corporation Copyright © 2003, Data Access Technologies, Inc. Copyright © 2003, DSTC Copyright © 2003, Gentleware Copyright © 2003, Hewlett-Packard Copyright © 2003, International Business Machines Copyright © 2003, IONA Copyright © 2003, MetaMatrix Copyright © 2015, Object Management Group Copyright © 2003, Softeam Copyright © 2003, SUN Copyright © 2003, Telelogic AB Copyright © 2003, Unisys USE OF SPECIFICATION - TERMS, CONDITIONS & NOTICES The material in this document details an Object Management Group specification in accordance with the terms, conditions and notices set forth below. This document does not represent a commitment to implement any portion of this specification in any company's products. The information contained in this document is subject to change without notice. LICENSES The companies listed above have granted to the Object Management Group, Inc. (OMG) a nonexclusive, royalty-free, paid up, worldwide license to copy and distribute this document and to modify this document and distribute copies of the modified version. Each of the copyright holders listed above has agreed that no person shall be deemed to have infringed the copyright in the included material of any such copyright holder by reason of having used the specification set forth herein or having conformed any computer software to the specification.
    [Show full text]
  • Metaclasses 4 ◆ Dynamic Binding Implies That Classes Must Have Some ◆ Meta-: Beyond; Transcending; More Comprehensive; E.G., As Memory Representation
    ® 1 ® Class Representation in Memory? 2 Case Study: Meta Classes ◆ A class is an abstract entity, so why should it be represented in the runtime environment? ◆ Answer: Dynamic Binding! ◆ Class representation in memory ● The actual method bound to a message is determined at run time based on the type (class) of an object. ◆ Class variables and class methods ● There must be a link between the object and its ◆ Meta Classes methods. ● Since these links are the same for all objects of the ◆ 3 Level System same class, it makes sense to share the representation. ◆ ◆ 4 Level System Schematic diagram, common to all OO languages: Method ◆ 5 Level System 1 Method ◆ 1 Level System Class Rep 2 ◆ Msg Object Methods Infinite Levels System Table Methodn oop Õ Ö oop Õ Ö ® A Class as an Object? 3 ® Metaclasses 4 ◆ Dynamic binding implies that classes must have some ◆ Meta-: Beyond; transcending; more comprehensive; e.g., as memory representation. in metalinguistics. ◆ Why not as an object? ◆ Class: generates instances. ◆ Answer: Let's go for it! ◆ Metaclass: a class whose instances are classes. ● Each object o has a pointer to its class object c which is the ◆ Terminal Instance: cannot be instantiated further. object representing the class to which o belongs. Objects Class Classes Terminal Instances Novel Play Instantiable objects Non instantiable objects Macbeth Othello Metaclasses Instances are classes 1984 War & Peace As you like Main Text Book Reference: G.Masini et al. Oliver Twist Object-Oriented Languages, APIC series, No.34 oop Õ Ö oop Õ Ö ® 5 ® 6 Taxonomy of Metaclass Systems The 3 Level System ◆ 1-Level System: Objects only Object ● Each object describes itself INSTANCE _OF ● No need for classes: objects are ìinstantiatedî or ìinheritedî from SUBCLASS _OF other objects Class Example: Self VARIABLES instance_of ,167$1&(B2) ◆ 2-Level System: Objects, Classes METHODS ..
    [Show full text]
  • The Cool Reference Manual∗
    The Cool Reference Manual∗ Contents 1 Introduction 3 2 Getting Started 3 3 Classes 4 3.1 Features . 4 3.2 Inheritance . 5 4 Types 6 4.1 SELF TYPE ........................................... 6 4.2 Type Checking . 7 5 Attributes 8 5.1 Void................................................ 8 6 Methods 8 7 Expressions 9 7.1 Constants . 9 7.2 Identifiers . 9 7.3 Assignment . 9 7.4 Dispatch . 10 7.5 Conditionals . 10 7.6 Loops . 11 7.7 Blocks . 11 7.8 Let . 11 7.9 Case . 12 7.10 New . 12 7.11 Isvoid . 12 7.12 Arithmetic and Comparison Operations . 13 ∗Copyright c 1995-2000 by Alex Aiken. All rights reserved. 1 8 Basic Classes 13 8.1 Object . 13 8.2 IO ................................................. 13 8.3 Int................................................. 14 8.4 String . 14 8.5 Bool . 14 9 Main Class 14 10 Lexical Structure 14 10.1 Integers, Identifiers, and Special Notation . 15 10.2 Strings . 15 10.3 Comments . 15 10.4 Keywords . 15 10.5 White Space . 15 11 Cool Syntax 17 11.1 Precedence . 17 12 Type Rules 17 12.1 Type Environments . 17 12.2 Type Checking Rules . 18 13 Operational Semantics 22 13.1 Environment and the Store . 22 13.2 Syntax for Cool Objects . 24 13.3 Class definitions . 24 13.4 Operational Rules . 25 14 Acknowledgements 30 2 1 Introduction This manual describes the programming language Cool: the Classroom Object-Oriented Language. Cool is a small language that can be implemented with reasonable effort in a one semester course. Still, Cool retains many of the features of modern programming languages including objects, static typing, and automatic memory management.
    [Show full text]
  • Generic Immutability and Nullity Types for an Imperative Object-Oriented Programming Language with flexible Initialization
    Generic Immutability and Nullity Types for an imperative object-oriented programming language with flexible initialization James Elford June 21, 2012 Abstract We present a type system for parametric object mutability and ref- erence nullity in an imperative object oriented language. We present a simple but powerful system for generic nullity constraints, and build on previous work to provide safe initialization of objects which is not bound to constructors. The system is expressive enough to handle initialization of cyclic immutable data structures, and to enforce their cyclic nature through the type system. We provide the crucial parts of soundness ar- guments (though the full proof is not yet complete). Our arguments are novel, in that they do not require auxiliary runtime constructs (ghost state) in order to express or demonstrate our desired properties. 2 Contents 1 Introduction 4 1.1 In this document . .5 2 Background 6 2.1 Parametric Types . .6 2.1.1 Static Polymorphism through Templates . .7 2.1.2 Static Polymorphism through Generic Types . 12 2.2 Immutability . 18 2.2.1 Immutability in C++ .................... 19 2.2.2 Immutability in Java and C# ............... 21 2.2.3 An extension to Java's immutability model . 21 2.2.4 Parametric Immutability Constraints . 24 2.3 IGJ: Immutability Generic Java .................. 25 2.4 Nullity . 27 2.5 Areas of commonality . 30 3 Goals 32 4 Existing systems in more detail 34 4.1 The initialization problem . 34 4.2 What do we require from initialization? . 35 4.3 Approaches to initialization . 37 4.4 Delay Types and initialization using stack-local regions .
    [Show full text]