ebook img

Object-Oriented Programming A Unified Foundation PDF

371 Pages·1996·27.146 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Object-Oriented Programming A Unified Foundation

Progress in Theoretical Computer Science Editor Ronald V. Book, University of California Editorial Board Erwin Engeler, ETH Zentrum, Zurich, Switzerland Jean-Pierre Jouannaud, Universite de Paris-Sud, Orsay, France Robin Milner, Cambridge University, England Martin Wirsing, UniversiHit Passau, Passau, Germany Giuseppe Castagna Object-Oriented Programming A Unified Foundation Birkhauser Boston • Basel • Berlin Giuseppe Castagna CNRS LIENS Ecole Normale Superieure 75005 Paris France Library of Congress Cataioging-in-Publication Data Castagna, Giuseppe, 1966- Object-oriented programming: a unified foundation / Giuseppe Castagna. p. cm. -- (Progress in theoretical computer science) Includes bibliographical references (p. 345-357) ISBN-13: 978-1-4612-8670-7 e-ISBN-13: 978-1-4612-4138-6 DOl: 10.107/978-1-4612-4138-6 paper) 1. Object-oriented programming (Computer science) 2. Programming languages (Electronic computers) I. Title. II. Series. QA76.64.C372 1997 005.13--dc20 96-33163 CIP Printed on acid-free paper ~ © 1997 Birkhauser Boston Birkhiiuser lL(J2) Softcover reprint of the hardcover 1st edition 1997 Copyright is not claimed for works of U.S. Government employees. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior permission of the copyright owner. Permission to photocopy for internal or personal use of specific clients is granted by Birkhauser Boston for libraries and other users registered with the Copyright Clearance Center (CCC), provided that the base fee of$6.00 per copy, plus $0.20 per page is paid directly to CCC, 222 Rosewood Drive, Danvers, MA 01923, U.S.A. Special requests should be addressed directly to Birkhauser Boston, 675 Massachusetts Avenue, Cambridge, MA 02139, U.S.A. Typeset by the author in LATEX. 9 8 7 6 5 4 3 2 1 Contents Foreword (by Luca Cardelli) xiii Presentation of the book xv I Introduction 1 1 Background and notation 3 1.1 A-notation . . . . . . ....... 3 1.1.1 The origins of A-calculus . 7 1.1.2 Data types .... 8 1.2 Simply-typed A-calculus 9 1.2.1 Reduction. 10 1.2.2 Typing ..... 12 1.2.3 Properties . . . . 14 1.2.4 Fixed point operators . 17 1.3 Subtyping ........ 18 1.3.1 The ~-calculus 18 1.3.2 Records ...... 27 1.3.3 Cartesian products 28 1.3.4 Recursive types . 29 1.4 Further definitions. . . . . 30 1.4.1 Algebra ...... 30 1.4.2 Term rewriting systems . 31 1.4.3 Logic .......... 33 2 A quick overview 35 ......... 2.1 Introduction . 35 2.2 Object-oriented programming 40 2.3 The A&-calculus ....... 44 2.4 Covariance and contravariance 51 2.5 Strong normalization ..... 54 vi CONTENTS 2.6 Three variations on the theme. . . . . . . . 55 2.7 Interpretation of object-oriented languages. 58 2.8 Imperative features 62 2.9 Semantics.......... 63 2.10 Second-order . . . . . . . . 66 2.11 Second order overloading . . 68 2.12 Ft- and object-oriented programming 71 2.13 Conclusion ....... . . . . . . . 75 II Simple typing 77 3 Object-oriented programming 79 3.1 A kernel object-oriented language 80 3.1.1 Objects.......... 80 3.1.2 Messages......... 80 3.1.3 Methods versus functions 81 3.1.4 Classes ...... . 83 3.1.5 Inheritance........ 85 3.1.6 Multiple inheritance .. . 88 3.1. 7 Implementation of message-passing 90 3.1.8 Extending classes. . . . . . . . . . 90 3.1.9 Self, super and the use of coercions 92 3.1.10 First-class messages: adding overloading 95 3.1.11 Multi-methods 97 3.2 Type checking . . . . . . . . 98 3.2.1 The types ..... . 98 3.2.2 Intuitive typing rules 99 3.3 Object-oriented programming ala CLOS . 102 3.3.1 Classes ...... . 102 3.3.2 Methods ..... . 103 3.3.3 Multiple dispatching 105 3.3.4 Super and coerce 105 3.3.5 Types 106 3.4 Comparison .... . 106 3.5 Conclusion .... . 108 3.6 Bibliographical notes 111 4 The It&-calculus 113 4.1 Informal presentation . . . . . . . . . . . . . . . . 113 4.1.1 Subtyping, run-time types and late binding 114 4.2 The syntax of It&-calculus 116 4.2.1 Subtyping system . . 117 4.2.2 Types........ 118 CONTENTS vii 4.2.3 Tenns...... 119 4.2.4 Type system .. 120 4.2.5 Reduction Rules 123 4.3 Soundness of the type system . 126 4.4 Church-Rosser 129 4.5 Basic encodings . . . . 132 4.5.1 Products ... 132 4.5.2 Simple records 132 4.5.3 Updatable records 133 4.6 A& and object-oriented programming 135 4.6.1 The "objects as records" analogy. 137 4.6.2 Inheritance . . . . . . . . . . . . 139 4.6.3 Binary methods and multiple dispatch 141 4.6.4 Covariance vs. contravariance 143 4.6.5 Class extension . . . 143 4.6.6 First class messages 144 4.6.7 Abstract classes. 144 4.7 Related work . . . . . . . . 147 5 Covariance and contravariance: conflict without a cause 153 5.1 Introduction ................ . 154 5.2 The controversy . . . . . . . . . . . . . . . 154 5.3 Covariance in the overloading-based model 157 5.4 Covariance in the record-based model 159 5.5 Practical aspects . 163 5.6 Conclusion .. . 165 6 Strong Normalization 167 6.1 The full calculus is not nonnalizing 167 6.2 Fixed point combinators ..... 168 6.3 The reasons for non nonnalization 169 6.4 Typed-inductive properties . . . . . 171 6.5 Strong Nonnalization is typed-inductive 175 7 Three variations on the theme 177 7.1 Adding explicit coercions . 177 7.1.1 Properties..... 179 7.1.2 More on updatable records 181 7.2 More freedom to the system: A&+ ..... 182 7.3 Unifying overloading and A-abstraction: A{ } 185 7.3.1 Subject Reduction 187 7.3.2 Church-Rosser 188 7.4 Reference to other work. . 191 viii CONTENTS 8 Interpretation of object-oriented languages 193 8.1 Formal presentation of KOOL ... 194 8.1.1 The terms of the language 195 8.1.2 The types of the language 197 8.2 It_object ........ . 204 8.2.1 The type system 209 8.2.2 Some results .. 211 8.3 Translation ...... . 213 8.3.1 Correctness of the type-checking. . 215 8.3.2 Some remarks. . . . . . . 215 8.4 It_object and It& ........ . 216 8.4.1 The encoding of the types 216 8.4.2 The encoding of the terms 219 9 Imperative features and other widgets 221 9.1 Imperative features ...... . 221 9.1.1 Imperative KOOL .. . 223 9.1.2 Imperative 1t&-ca1culus 224 9.1.3 Interpretation 226 9.2 Unique application 228 9.3 Signatures ..... . 229 10 Semantics 235 10.1 Introduction . 235 10.2 The completion of overloaded types 236 10.3 Early Binding ..... . 240 10.4 Semantics . . . . . . . . . . . . . . 242 10.4.1 PER as a model . . . . . . . 242 10.4.2 Overloaded types as Products 246 10.4.3 The semantics of terms . 250 10.5 Summary of the semantics 256 III Second order 259 11 Introduction to part III 261 11.1 Loss of information in the record-based model . 262 11.1.1 Implicit Polymorphism . 263 11.1.2 Explicit Polymorphism . . . . . . 263 11.2 F$. .................... . 265 11.2.1 Subtyping and typing algorithms . 267 11.3 Furtherfeatures . . . . . . . . . . . . . . 269 11.3.1 Records and update ....... . 269 11.3.2 Quantification over recursive types. 270 CONTENTS ix 11.3.3 F-bounded quantification . 271 11.3.4 Existential quantification . 272 12 Second order overloading 275 12.1 Loss of information in the overloading -based model . 275 12.1.1 Type dependency . . 277 12.2 Type system. . . . . . . . . . . 279 12.2.1 Some useful results. . . 281 12.2.2 Transitivity elimination . 282 12.2.3 Subtyping algorithm and coherence of the system . 288 12.3 Terms 291 12.4 Reduction . . . . . . . . . . . . . . . . . . . 293 12.4.1 Soundness of the type system 294 12.4.2 Church-Rosser . . . . . . . . . . . 308 13 Second order overloading and object-oriented programming 313 13.1 Object-oriented programming ......... 313 13.1.1 Extending classes. . . . . . . . . . . . 316 13.1.2 First class messages, super and coerce . 316 13.1.3 Typing rules for polymorphic KOOL 317 13.1.4 Multiple dispatch. 319 13.1.5 Advanced features 320 13.2 Conclusion ........ 322 14 Conclusion 323 14.1 Object-oriented programming 323 14.2 Proof Theory . . . . . . . . . 324 14.3 Beyond object-oriented programming 326 IV Appendixes 329 A Specification of KOOL 331 A.l Terms .. . 331 A.2 Pretypes ..... . 332 A.3 Subtyping . . . . . 332 A.4 Auxiliary Notation 333 A.5 Typing Rules ... 333 B Formal definition of the translation 335 B.l Without mutually recursive methods 336 B.2 With recursive methods . . . . . . 338 B.3 Overloaded functions ...... . 339 B.4 Correctness of the type-checking . 340 x CONTENTS Bibliography 345 Index 358

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.