Programming with Types

Programming with Types

PROGRAMMING WITH TYPES A Dissertation Presented to the Faculty of the Graduate School of Cornell University in Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy by Stephanie Claudene Weirich August 2002 c Stephanie Claudene Weirich 2002 ALL RIGHTS RESERVED PROGRAMMING WITH TYPES Stephanie Claudene Weirich, Ph.D. Cornell University 2002 Run-time type analysis is an increasingly important linguistic mechanism in modern programming languages. Language runtime systems use it to implement services such as accurate garbage collection, serialization, cloning and structural equality. Component frameworks rely on it to provide reflection mechanisms so they may discover and interact with program interfaces dynamically. Run-time type analysis is also crucial for large, distributed systems that must be dynami- cally extended, because it allows those systems to check program invariants when new code and new forms of data are added. Finally, many generic user-level al- gorithms for iteration, pattern matching, and unification can be defined through type analysis mechanisms. However, existing frameworks for run-time type analysis were designed for sim- ple type systems. They do not scale well to the sophisticated type systems of mod- ern and next-generation programming languages that include complex constructs such as first-class abstract types, recursive types, objects, and type parameteri- zation. In addition, facilities to support type analysis often require complicated language semantics that allow little freedom in their implementation. This dis- sertation investigates the foundations of run-time type analysis in the context of statically-typed, polymorphic programming languages. Its goal is to show how such a language may support type-analyzing operations in a way that balances expressiveness, safety and simplicity. BIOGRAPHICAL SKETCH Stephanie Weirich is from Farmers Branch, Texas. She received a B.A. from Rice University in 1996 and an M.S. from Cornell University in 2000. Portions of her graduate studies at Cornell were supported by a National Science Foundation Fellowship and an Intel Fellowship. She participated in the Distributed Mentorship Program, sponsored by the Computing Research Association, during Summer 1996 and in the internship program at Bell Labs, Lucent Technologies during Summer 1999. Stephanie is married to Steve Zdancewic and in Fall 2002 they both will join the Computer and Information Science Department at the University of Pennsylvania, in Philadelphia, Pennsylvania. iii ACKNOWLEDGEMENTS This dissertation would not have been written without the support from many people. First of all my family. My parents Wayne and Charlotte Weirich are my inspiration. My husband Steve Zdancewic deserves much credit, for reasons too numerous to list. Steve’s parents Arthur and Deborah Zdancewic have encouraged me as long as I have known them. I have received much guidance from my advisors, official and otherwise. Greg Morrisett and Karl Crary were extremely influential to this dissertation and to my own professional development. However, I have been getting advice for a long time, and I am also thankful for the wisdom of Matthias Felleisen, Devika Subramanian, Keith Cooper, Bob Constable, Dexter Kozen, and John Reppy. Life in Ithaca would not be fun without a number of people. My officemates Dave Walker and Nick Howe somehow put up with me for four years. Dan Gross- man provided me with coffee filters. Mike Hicks taught me everything I know about dynamic linking. James Cheney, Jim Ezick, Neal Glew, Jason Hickey, Ric- cardo Pucella, Fred Smith, Yan-ling Wang, and Vicky Weissman made Cornell a great place to study and discuss programming languages. Jennifer Bishop, Lyn Millet, Susannah Howe and Amanda Holland-Minkley made Ithaca a great place to discuss books. I have also been fortunate to share Ithaca with Bert Adams, Gary Adams, Tu¸gkan Batu, Adam Florence, Annette Florence, Takako Hickey, Kim Hicks, Timmy Hicks, Jon Kleinberg, Lillian Lee, Tobias Mayr, Tanya Mor- risett, Patrick White and Alyson White. Stephanie Weirich July, 2002 iv TABLE OF CONTENTS 1 Introduction 1 1.1 Language support for run-time type analysis . 3 1.1.1 Previous approach: Dynamically typed languages . 5 1.1.2 Previous approach: Reflecting types as data . 6 1.1.3 Previous approach: Dynamic types and typecase . 9 1.1.4 Previous approach: Intensional polymorphism . 10 1.1.5 Previous approach: Polytypic programming . 12 1.2 An ideal language . 13 1.3 Dissertation outline and contributions . 16 1.4 Reflection . 18 2 Background: A calculus for dynamic type dispatch 20 2.1 Examples of type analysis . 20 2.1.1 Data representation . 21 2.1.2 Polymorphic equality . 22 2.1.3 Run-time type checking and dynamic types . 23 2.1.4 Reflecting functions . 26 2.2 The LI language . 27 2.2.1 LI Syntax . 27 2.2.2 Core language . 28 2.2.3 Operational semantics . 36 2.3 Type analysis operators . 38 2.4 Formalizing the examples . 43 2.5 Typing properties of LI . 46 2.5.1 Decidable type checking . 46 2.5.2 Type soundness . 47 2.6 Discussion and chapter summary . 49 v 3 Type analysis without analyzing types 51 3.1 Type-passing vs. type-erasure semantics . 51 3.2 Term representations of types . 53 3.2.1 A quick example . 57 3.3 Typing properties of LIR . 57 3.4 Embedding of LI . 61 3.4.1 Properties of the embedding . 63 3.5 Discussion and chapter summary . 82 4 Type analysis without hard-wired types (I) 84 4.1 Introduction . 84 4.1.1 Type analysis in typed compilation . 84 4.1.2 Type analysis as a programming idiom . 86 4.1.3 Informal presentation . 86 4.2 A Language for flexible type analysis . 88 4.2.1 Kinds and Constructors . 89 4.2.2 Terms . 91 4.2.3 Static semantics . 95 4.2.4 Properties of LX . 101 4.3 Programming type analysis . 103 4.3.1 Types with binding structure . 105 4.4 Type erasure . 106 4.4.1 Type soundness of constructor representation . 113 4.4.2 Encoding of LIR . 118 4.5 Discussion and chapter summary . 122 5 Type analysis without hard-wired types (II) 123 5.1 Eliminating type analysis . 123 5.1.1 Encoding datatypes with polymorphism . 123 5.2 Source and target language details . 125 5.3 Defining iteration . 131 5.3.1 Properties of the embedding . 133 5.4 Discussion . 138 5.4.1 Extension to an R-constructor . 138 5.4.2 Extension to primitive recursion . 139 5.4.3 Impredicativity and non-termination . 140 5.4.4 Related work . 141 vi 6 Higher-order type analysis 142 6.1 Polytypic programming . 142 6.1.1 Higher-order polytypism . 144 6.2 The semantics of higher-order typerec: The LH language . 148 6.2.1 Recursive types . 152 6.2.2 F2 polymorphism . 156 6.2.3 Typing properties of LH . 156 6.2.4 Model theoretic properties . 160 6.3 Multiplace logical relations . 163 6.3.1 Example: map . 164 6.3.2 Example: typetostring . 165 6.4 Kind polymorphism . 165 6.4.1 Analysis of polymorphic types . 168 6.4.2 Example: typetostring . 169 6.5 Related work . 170 6.6 Chapter summary . 171 7 Representing higher-order type analysis 172 7.1 Kind-directed execution: The LK language . 172 7.1.1 Typing properties of LK . 174 7.1.2 Correspondence with LH . 175 7.2 Phase-splitting LK . 179 7.2.1 A parameterized representation type . 181 7.2.2 Defining term representations of type constructors . 182 7.3 The LKR language . 183 7.3.1 Static semantics . 183 7.3.2 Dynamic semantics . 185 7.4 An example . 186 7.5 Typing properties of LKR . 188 7.6 Correctness of the embedding of LK . 192 7.6.1 Static correctness . 192 7.6.2 Dynamic correctness . 196 7.7 An alternative version . 203 7.8 Chapter summary . 205 8 Summary and Directions for Future Research 206 8.1 Future directions in type analysis . 207 8.1.1 Type-level type analysis . 207 8.1.2 Structural type analysis in practice . 208 8.2 Future application areas . 208 vii 8.2.1 Type-based program verification . 208 8.2.2 Extension frameworks for statically-typed languages . 208 BIBLIOGRAPHY 210 viii LIST OF TABLES 1.1 Languages described in this dissertation . 16 2.1 LI: Syntax . 28 2.2 LI: Judgment forms . 30 2.3 Core language: Static semantics . 31 2.4 Core language: Operational semantics . 36 2.5 LI: Operational semantics of typerec .................. 38 2.6 LI: Schema for typerec branches . 39 2.7 LI: Static semantics of typerec ..................... 40 2.8 LI: Static semantics of Typerec .................... 40 2.9 LI: Constructor reduction . 42 3.1 LIR: Syntax . 54 3.2 LIR: Representation types . 54 3.3 LIR: Operational semantics of typerec ................. 55 3.4 LIR: Static semantics . 56 3.5 Translation of LI types and terms . 61 3.6 Translation of LI constructors . 62 3.7 Translation of LI contexts . 63 3.8 Extended representations . 67 3.9 Extended translation . 68 4.1 LX: Syntax for kinds and constructors . 89 4.2 LX: Syntax for terms and values . ..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    238 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us