Thông tin tài liệu
TEAMFLY
Team-Fly
®
Foundations
of
Object-Oriented
Languages
This page intentionally left blank
Foundations
of
Object-Oriented
Languages
Types
and
Semantics
Kim B. Bruce
The MIT Press
Cambridge, Massachusetts
London, England
© 2002 Massachusetts Institute of Technology
All rights reserved. No part of this book may be reproduced in any form by any
electronic or mechanical means (including photocopying, recording, or information
storage and retrieval) without permission in writing from the publisher.
Library of Congress Cataloging-in-Publication Information
Bruce, Kim B.
Foundations of object-oriented languages: types a nd semantics /
Kim B. Bruce.
p. cm.
Includes bibliographical references and index.
ISBN 0-262-02523-X (hc. : alk. paper)
1. Object-oriented programming (computer science). 2. Programming lan-
guages (Electronic computers). I. T itle.
QA76.64 .B776 2002
005.1’17–dc21 2001054613
To my mother and t he memory of my late father
This page intentionally left blank
Contents
List of Figures xi
Preface xv
ITypeProblemsin
Object-Oriented Languages 1
1 Introduction 3
1.1 Type systems in programming languages 4
1.2 Type checking and strongly typed languages 6
1.3 Focus on statically typed class-based languages 12
1.4 Foundations: A look ahead 13
2 Fundamental Concepts of Object-Oriented Languages 17
2.1 Objects, classes, and object types 17
2.2 Subclasses and inheritance 22
2.3 Subtypes 24
2.4 Covariant and contravariant changes in types 26
2.5 Overloading versus overriding methods 27
2.6 Summary 32
3 Type Problems in Object-Oriented Languages 33
3.1 Type checking object-oriented languages is difficult 33
3.2 Simple type systems are lacking in flexibility 35
3.3 Summary of typing problems 48
4 Adding Expressiveness to Object-Oriented Languages 49
viii Contents
4.1 GJ 49
4.2 Even more flexible typing with Eiffel 60
4.3 Summary 69
5 Understanding Subtypes 71
5.1 Subtyping for non-object types 72
5.2 Object types 83
5.3 Subtyping for class types 84
5.4 Summary 86
6 Type Restrictions on Subclasses 89
6.1 Allowable changes to method types 89
6.2 Instance variable types invariant in subclasses 91
6.3 Changing visibility 92
6.4 Summary 93
7 Varieties of Object-Oriented Programming Languages 95
7.1 Multi-methods vs. object-based vs. class-based languages 95
7.2 Well-known object-orient ed languages 103
7.3 Summary 111
Historical Note s and References for Section I 113
II Foundations:
The Lambda Calculus 117
8 Formal Language Descriptions and the Lambda C alculus 119
8.1 The simply-typed lambda calculus 120
8.2 Adding pairs, sums, records, and references 132
8.3 Summary 140
9 The Polymorphic Lambda Calculus 141
9.1 Parameterized types and polymorphism 141
9.2 Recursive expressions and types 147
9.3 Information hiding and existential types 151
9.4 Adding subtypes to the polymorphic lambda calculus 156
9.5 Summary 165
Historical Note s and References for Section II 167
Contents ix
III Formal Descriptions of
Object-Oriented Languages 171
10 , a Simple Object-Oriented Language 173
10.1 Informal description and example 173
10.2 Syntax and type-checking rules 176
10.3 Summary 200
11 A Simple Translational Semantics of Objects and Classes 201
11.1 Representing objects at runtime 201
11.2 Modeling
types in 203
11.3 Modeling
expressions in 207
11.4 Modeling classes — first try 212
11.5 Problems with modeling subclasses 218
11.6 Summary 223
12 Improved Semantics for Classes 225
12.1 (Re-)Defining classes 225
12.2 A correct subclass encoding 232
12.3 Summary and a look ahead 233
13
’s Type System Is Safe (and Sound) 239
13.1 The translation of
to is sound 239
13.2 The translation is well defined 255
13.3 is type safe 258
13.4 Errors 260
13.5 Summary 262
14 Completing
:
super
,
nil
, Information Hiding, and Multiple
Inheritance 263
14.1 Using methods from superclasses 263
14.2 Translating nil 266
14.3 A complication with self 271
14.4 Finer control over information hiding 272
14.5 Multiple inheritance 275
14.6 Summary 279
Historical Note s and Refere nces for Section III 283
[...]... definition of a simple object-oriented language, ËÇÇÄ, and its type system Chapters 11 and 12 explore understanding the semantics of ËÇÇÄ by translating terms into a very rich extension of the typed lambda calculus With this understanding of the language, Chapter 13 presents a proof of soundness and safety of ËÇÇÄ This chapter is the technically most difficult of the book The details of the proof in the... from other recent books in the foundations of objectoriented languages in several ways First, the focus of attention is classbased object-oriented languages, rather than object-based or multi-method languages Thus our study is very relevant to the most popular kind of object-oriented languages in use today Second, this book approaches the foundations from the point of view of a programmer or language... expressions of ËÇÇÄ, part 1 Type-checking rules for expressions of ËÇÇÄ, part 2 Type-checking rules for statements of ËÇÇÄ Subtyping rules for ËÇÇÄ Class definition from PointExample 174 175 182 183 184 185 188 189 192 194 195 197 List of Figures 11.1 11.2 11.3 11.4 12.1 12.2 Translation of types of ËÇÇÄ to types in £È Translation of selected expressions of ËÇÇÄ to expressions in £È Translation of more... developments in the foundations of object-oriented languages It can be used as the main text for a course in the foundations of object-oriented programming languages or as a supplementary text for a course with a broader focus that includes object-oriented programming languages We have designed the first part of the book, comprising the first seven chapters, to be especially accessible to a wide variety of readers... £È Translation of selected expressions of ËÇÇÄ to expressions in £È Final translation of expressions of ËÇÇÄ to £È Part 2 Translation of statements of ËÇÇÄ to expressions in £È 13.1 CellExample program 256 12.3 12.4 12.5 12.6 12.7 14.1 14.2 14.3 14.4 14.5 14.6 Type-checking rules for subclasses with super Translation of subclass with super from ËÇÇÄ to £È Illustration of the use of super in a subclass... interest in the extension, GJ, of Java described in Section 4.1 provides evidence that this kind of technology transfer has already begun The material presented in this book is the result of the dedicated and creative work of many researchers The Historical Notes and References sections at the end of each of the four parts of the book credit the contributions of Preface xix many of those doing research in... expressiveness of statically typed languages Examples of statically type-safe, yet flexible, procedural and functional programming languages include Clu, Modula-2, Ada, ML, and Haskell Unfortunately the situation for static type checking in object-oriented languages is not as good The following is a list of some properties of typechecking systems of some of the more popular object-oriented languages (or the object-oriented. .. part of the book with a discussion of different kinds of object-oriented languages (e.g., class-based, object-based, and multi-method languages) and an examination of statically typed object-oriented languages Simula 67, Beta, Java, C++, Smalltalk, Eiffel, and Sather with reference to our model languages and type systems In order to support a careful analysis of the type systems and semantics of object-oriented. .. semantics of object-oriented languages, we will introduce a prototypical object-oriented language, ËÇÇÄ, with a simple type system that is similar to those of classbased object-oriented languages in common use today After a discussion of subtypes and subclasses (especially with regard to type restrictions on overriding methods), we begin an analysis of the foundations of object-oriented languages by... statements of ËÇÇÄ to expressions in £È Translation of class and new expressions of ËÇÇÄ to expressions in £È xiii 203 209 211 218 227 12.8 12.9 Revised type-checking rules for classes and subclasses Revised type-checking rules for messages and instance variables New translation of classes and class types New translation of new expressions New translation of subclasses Final translation of types of ËÇÇÄ . under-
standing of the foundations of object-oriented programming languages, and
to researchers who wish to understand developments in the foundations of
object-oriented. 197
List of Figures xiii
11.1 Translation of types of
to types in . 203
11.2 Translation of selected expressions of
to expressions in
. 209
11.3 Translation of
Ngày đăng: 20/03/2014, 15:39
Xem thêm: foundations of object-oriented languages, 2002