
Portland State University PDXScholar Dissertations and Theses Dissertations and Theses Spring 6-6-2017 Fully Generic Programming Over Closed Universes of Inductive-Recursive Types Larry Diehl Portland State University Follow this and additional works at: https://pdxscholar.library.pdx.edu/open_access_etds Part of the Computer Sciences Commons Let us know how access to this document benefits ou.y Recommended Citation Diehl, Larry, "Fully Generic Programming Over Closed Universes of Inductive-Recursive Types" (2017). Dissertations and Theses. Paper 3647. https://doi.org/10.15760/etd.5531 This Dissertation is brought to you for free and open access. It has been accepted for inclusion in Dissertations and Theses by an authorized administrator of PDXScholar. Please contact us if we can make this document more accessible: [email protected]. Fully Generic Programming Over Closed Universes of Inductive-Recursive Types by Larry Diehl A dissertation submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy in Computer Science Dissertation Committee: Tim Sheard, Chair James Hook Mark P. Jones Andrew Tolmach Robert Bass Portland State University 2017 i ABSTRACT Dependently typed programming languages allow the type system to express arbitrary propositions of intuitionistic logic, thanks to the Curry-Howard isomor- phism. Taking full advantage of this type system requires defining more types than usual, in order to encode logical correctness criteria into the definitions of datatypes. While an abundance of specialized types helps ensure correctness, it comes at the cost of needing to redefine common functions for each specialized type. This dissertation makes an effort to attack the problem of code reuse in de- pendently typed languages. Our solution is to write generic functions, which can be applied to any datatype. Such a generic function can be applied to datatypes that are defined at the time the generic function was written, but they can also be applied to any datatype that is defined in the future. Our solution builds upon previous work on generic programming within dependently typed programming. Type theory supports generic programming using a construction known as a universe. A universe can be considered the model of a programming language, such that writing functions over it models writing generic programs in the programming language. Historically, there has been a trade-off between the expressive power of the modeled programming language, and the kinds of generic functions that can be written in it. Our dissertation shows that no such trade-off is necessary, and that we can write future-proof generic functions in a model of a dependently typed programming language with a rich collection of types. ii ACKNOWLEDGMENTS I would like to thank Tim Sheard, my advisor, for giving me the freedom to ex- plore my own research interests, for always being available to listen and provide constructive feedback, and for instilling in me the importance of thoroughly ex- plaining background material, supplemented by plenty of examples. I would also like to thank my parents, for supporting my decision to pursue aca- demic interests, despite needing to abandon a lucrative job and career in software development. Finally, I would like to thank Conor McBride, for inspiring me to work on the topic of generic programming. This inspiration is in part due to his academic publications and artifacts resulting from the Epigram programme, and is in part due to him warmly and enthusiastically welcoming a naive industry programmer. iii TABLE OF CONTENTS Abstract i Acknowledgments ii List of Figures ix Color Conventions x Part I Prelude 1 Chapter 1 Introduction 2 1.1 Dependently Typed Languages & Motivation . 3 1.1.1 Curry-Howard Isomorphism . 3 1.1.2 Indexed Types . 5 1.1.3 Motivation . 6 1.2 A Taste of Fully Generic Programming . 6 1.2.1 Traditional Generic Programming . 7 1.2.2 Fully Generic Programming . 9 1.2.3 Universes . 11 1.2.4 Fully Generic versus Deriving . 14 1.3 Class of Supported Datatypes . 14 1.3.1 Dependent Algebraic Types . 14 1.3.2 Indexing versus Induction-Recursion . 15 1.3.3 Smallness versus Largeness . 16 1.4 Thesis . 18 1.4.1 Thesis Statement . 18 1.4.2 Contributions . 19 1.4.3 Outline . 19 iv Chapter 2 Types & Universes 24 2.1 Types . 25 2.1.1 Function Types . 25 2.1.2 Non-Inductive Types . 26 2.1.3 Inductive Types . 27 2.1.4 Parameterized Types . 27 2.1.5 Indexed Types . 28 2.1.6 Type Families . 31 2.1.7 Derived Types . 31 2.1.8 Infinitary Types . 34 2.1.9 Inductive-Recursive Types . 35 2.1.10 Algebraic Types . 37 2.1.11 Computational Families . 38 2.1.12 Open Types . 39 2.1.13 Closed Types . 39 2.2 Universes . 40 2.2.1 Universe Model . 40 2.2.2 Open Universes . 41 2.2.3 Closed Universes . 43 2.2.4 Inductive Universes . 44 2.2.5 Non-Inductive Universes . 44 2.2.6 Subordinate Universes . 45 2.2.7 Autonomous Universes . 45 2.2.8 Derived Universes . 46 2.2.9 Parameterized Universes . 47 Chapter 3 Generic Programming 50 3.1 Parametric Polymorphism . 51 3.1.1 Parametric over Types . 51 3.1.2 Parametric over Levels . 51 3.2 Ad Hoc Polymorphism . 52 3.2.1 Ad Hoc by Overloading . 52 3.2.2 Ad Hoc by Coercion . 53 3.2.3 Ad Hoc by Overloading & Coercion . 54 3.3 Abstractness & Concreteness . 54 3.3.1 Abstract Types . 55 v 3.3.2 Concrete Types . 55 3.3.3 Abstract Data Types . 56 3.3.4 Fully Generic Programming . 56 3.4 Totality . 57 3.4.1 Non-Dependent Domain Change . 57 3.4.2 Non-Dependent Codomain Change . 58 3.4.3 Dependent Domain Change . 58 3.4.4 Dependent Codomain Change . 59 3.4.5 Domain Predicates versus Domain Supplements . 60 Chapter 4 Closed Type Theory 62 4.1 Closed Vector Universe . 63 4.1.1 Closed Vector Types . 63 4.1.2 Fully Generic Functions . 65 4.2 Closed Algebraic Universe . 69 4.2.1 Closed Well-Order Types . 70 4.2.2 Open Well-Order Types . 71 4.2.3 Inadequacy of Well-Orders . 73 Part II Open Type Theory 76 Chapter 5 Open Algebraic Universes 77 5.1 Open Non-Dependent Types . 79 5.1.1 Categorical Model . 79 5.1.2 Formal Model . 81 5.1.3 Examples . 86 5.2 Open Infinitary Types . 91 5.2.1 Categorical Model . 91 5.2.2 Formal Model . 93 5.2.3 Examples . 96 5.3 Open Dependent Types . 99 5.3.1 Categorical Model . 99 5.3.2 Formal Model . 102 5.3.3 Examples . 106 5.4 Open Inductive-Recursive Types . 111 5.4.1 Categorical Model . 112 vi 5.4.2 Formal Model . 117 5.4.3 Examples . 122 5.4.4 Agda Model . 131 Part III Closed Type Theory 133 Chapter 6 Closed Algebraic Universe 134 6.1 Open Inductive-Recursive Types . 135 6.1.1 Formal Model . 136 6.1.2 Source of Openness . 137 6.2 Closed Inductive-Recursive Types . 139 6.2.1 Formal Model . 139 6.2.2 Examples . 142 6.2.3 Kind-Generalized Universes . 150 6.3 How to Close a Universe . 152 6.3.1 Procedure . 152 6.3.2 Example Procedure Run . 153 6.4 Types versus Kinds . 157 6.4.1 Open Types and Kinds . 157 6.4.2 Gratuitous Kinds . 160 6.4.3 Types versus Descriptions . 161 6.4.4 Kind-Parameterized Types . 162 Chapter 7 Fully Generic Functions 167 7.1 Fully Generic Count . 169 7.1.1 Generic Types . 169 7.1.2 Counting All Values . 172 7.1.3 Counting Algebraic Arguments . 173 7.1.4 Examples . 176 7.2 Fully Generic Lookup . 185 7.2.1 Generic Types . ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages285 Page
-
File Size-