Category Theory and Lambda Calculus
Total Page:16
File Type:pdf, Size:1020Kb
Category Theory and Lambda Calculus Mario Román García Trabajo Fin de Grado Doble Grado en Ingeniería Informática y Matemáticas Tutores Pedro A. García-Sánchez Manuel Bullejos Lorenzo Facultad de Ciencias E.T.S. Ingenierías Informática y de Telecomunicación Granada, a 18 de junio de 2018 Contents 1 Lambda calculus 13 1.1 Untyped λ-calculus . 13 1.1.1 Untyped λ-calculus . 14 1.1.2 Free and bound variables, substitution . 14 1.1.3 Alpha equivalence . 16 1.1.4 Beta reduction . 16 1.1.5 Eta reduction . 17 1.1.6 Confluence . 17 1.1.7 The Church-Rosser theorem . 18 1.1.8 Normalization . 20 1.1.9 Standardization and evaluation strategies . 21 1.1.10 SKI combinators . 22 1.1.11 Turing completeness . 24 1.2 Simply typed λ-calculus . 24 1.2.1 Simple types . 25 1.2.2 Typing rules for simply typed λ-calculus . 25 1.2.3 Curry-style types . 26 1.2.4 Unification and type inference . 27 1.2.5 Subject reduction and normalization . 29 1.3 The Curry-Howard correspondence . 31 1.3.1 Extending the simply typed λ-calculus . 31 1.3.2 Natural deduction . 32 1.3.3 Propositions as types . 34 1.4 Other type systems . 35 1.4.1 λ-cube..................................... 35 2 Mikrokosmos 38 2.1 Implementation of λ-expressions . 38 2.1.1 The Haskell programming language . 38 2.1.2 De Bruijn indexes . 40 2.1.3 Substitution . 41 2.1.4 De Bruijn-terms and λ-terms . 42 2.1.5 Evaluation . 43 2.1.6 Principal type inference . 43 2.2 User interaction . 45 2.2.1 Monadic parser combinators . 45 2.2.2 Verbose mode . 46 2.2.3 SKI mode . 47 1 2.3 Usage . 48 2.3.1 Installation . 48 2.3.2 Mikrokosmos interpreter . 49 2.3.3 Jupyter kernel . 50 2.3.4 CodeMirror lexer . 50 2.3.5 JupyterHub . 53 2.3.6 Calling Mikrokosmos from Javascript . 53 2.4 Programming environment . 54 2.4.1 Cabal, Stack and Haddock . 54 2.4.2 Testing . 54 2.4.3 Version control and continuous integration . 56 2.5 Programming in untyped λ-calculus . 57 2.5.1 Basic syntax . 57 2.5.2 A technique on inductive data encoding . 58 2.5.3 Booleans . 58 2.5.4 Natural numbers . 59 2.5.5 The predecessor function and predicates on numbers . 60 2.5.6 Lists and trees . 60 2.5.7 Fixed points . 62 2.6 Programming in the simply typed λ-calculus . 63 2.6.1 Function types and typeable terms . 63 2.6.2 Product, union, unit and void types . 64 2.6.3 A proof in intuitionistic logic . 65 3 Category theory 67 3.1 Categories . 67 3.1.1 Definition of category . 67 3.1.2 Morphisms . 68 3.1.3 Products and sums . 69 3.1.4 Examples of categories . 70 3.2 Functors and natural transformations . 71 3.2.1 Functors . 71 3.2.2 Natural transformations . 72 3.2.3 Composition of natural transformations . 73 3.3 Constructions on categories . 75 3.3.1 Product categories . 75 3.3.2 Opposite categories and contravariant functors . 76 3.3.3 Functor categories . 77 3.4 Universality and limits . 78 3.4.1 Universal arrows . 78 3.4.2 Representability . 79 3.4.3 Yoneda Lemma . 79 3.4.4 Limits . 81 3.4.5 Examples of limits . 82 3.4.6 Colimits . 84 3.4.7 Examples of colimits . 85 3.5 Adjoints, monads and algebras . 86 3.5.1 Adjunctions . 86 3.5.2 Examples of adjoints . 90 2 3.5.3 Monads . 91 3.5.4 Algebras . 92 4 Categorical logic 95 4.1 Presheaves . 95 4.2 Cartesian closed categories and lambda calculus . 96 4.2.1 Lawvere theories . 96 4.2.2 Cartesian closed categories . 98 4.2.3 Simply-typed λ-theories . 99 4.2.4 Syntactic categories and internal languages . 100 4.3 Working in cartesian closed categories . 102 4.3.1 Diagonal arguments . 102 4.3.2 Bicartesian closed categories . 103 4.3.3 Inductive types . 104 4.4 Locally cartesian closed categories and dependent types . 105 4.4.1 Quantifiers and subsets . 105 4.4.2 Locally cartesian closed categories . 107 4.4.3 Dependent types . 109 4.4.4 Dependent pairs . 110 4.4.5 Dependent functions . 111 4.5 Working in locally cartesian closed categories . 112 4.5.1 Examples of dependent types . 112 4.5.2 Equality types . 114 4.5.3 Subobject classifier and propositions . 115 4.5.4 Propositional truncation . 115 4.6 Topoi . 116 4.6.1 Motivation . 116 4.6.2 An Elementary Theory of the Category of Sets . 117 5.