Total Haskell Is Reasonable Coq

Total Page:16

File Type:pdf, Size:1020Kb

Total Haskell Is Reasonable Coq Total Haskell is Reasonable Coq Antal Spector-Zabusky Joachim Breitner Christine Rizkallah Stephanie Weirich {antals,joachim,criz,sweirich}@cis.upenn.edu University of Pennsylvania Philadelphia, PA, USA Abstract However, Haskell programmers typically reason about We would like to use the Coq proof assistant to mechan- their code only informally. Most proofs are done on paper, ically verify properties of Haskell programs. To that end, by hand, which is tedious, error-prone, and does not scale. we present a tool, named hs-to-coq, that translates total On the other hand, the Coq proof assistant [22] is a great Haskell programs into Coq programs via a shallow embed- tool for writing proofs. It allows programmers to reason ding. We apply our tool in three case studies – a lawful Monad about total functional programs conveniently, efficiently, and instance, “Hutton’s razor”, and an existing data structure li- with high confidence. However, Coq lacks GHC’s extensive brary – and prove their correctness. These examples show ecosystem for program development. that this approach is viable: both that hs-to-coq applies Therefore, we propose a multimodal approach to the veri- to existing Haskell code, and that the output it produces is fication of total functional programs: write code in Haskell amenable to verification. and prove it correct in Coq. To support this plan, we have developed an automatic translator, called hs-to-coq, that CCS Concepts • Software and its engineering → Soft- allows this approach to scale. ware verification; For example, consider the standard map function on lists Keywords Coq, Haskell, verification (from the Haskell Prelude), and the list Functor instance. ACM Reference Format: map :: ¹a -> bº -> »a¼ -> »b¼ Antal Spector-Zabusky, Joachim Breitner, Christine Rizkallah, and map f » ¼ = » ¼ Stephanie Weirich. 2018. Total Haskell is Reasonable Coq. In Pro- map f ¹x : xsº = f x : map f xs ceedings of 7th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP’18). ACM, New York, NY, USA, 14 pages. instance Functor » ¼ where fmap = map https://doi.org/10.1145/3167092 Our tool translates this Haskell program automatically to the analogous Coq definitions. The map function becomes 1 Introduction the expected fixpoint. The Haskell programming language is a great tool for produc- ing pure, functional programs. Its type system tracks the use Definition map {a} {b} : ¹a -> bº -> list a -> list b := of impure features, such as mutation and IO, and its standard fix map arg_62__ arg_63__ library promotes the use of mathematically-inspired struc- := match arg_62__; arg_63__ with tures that have strong algebraic properties. At the same time, j ; nil => nil Haskell development is backed by an industrial-strength j f; cons x xs => cons ¹f xº ¹map f xsº end compiler (the Glasgow Haskell Compiler, GHC) [21], and . supported by mature software development tools, such as Similarly, the Functor type class in Haskell turns into a Coq IDEs and testing environments. type class of the same name, and Haskell’s Functor instance arXiv:1711.09286v1 [cs.PL] 25 Nov 2017 for lists becomes a type class instance on the Coq side. Once the Haskell definitions have been translated to Coq, users can prove theorems about them. For example, we pro- vide a type class for lawful functors: Class FunctorLaws ¹t : Type -> Typeº `{Functor t} := {functor_identity : forall a ¹x : t aº; fmap id x = x; CPP’18, January 8–9, 2018, Los Angeles, CA, USA functor_composition : © 2018 Copyright held by the owner/author(s). Publication rights licensed forall a b c ¹f : a -> bº ¹g : b -> cº ¹x : t aº; to the Association for Computing Machinery. This is the author’s version of the work. It is posted here for your personal fmap g ¹fmap f xº = fmap ¹g ◦ fº x} . use. Not for redistribution. The definitive Version of Record was published A list instance of the FunctorLaws type class is a formal in Proceedings of 7th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP’18), https://doi.org/10.1145/3167092. proof that the list type, using this definition of map, is a lawful functor. base-4.9.1.0: Basic libraries Source Contents Index Copyright (c) The University of Glasgow 2001 BSD-style (see the License file libraries/base /LICENSE) Maintainer [email protected] Stability provisional Portability portable Safe Trustworthy Haskell Language Haskell2010 Control.Monad The Functor, Monad and Contents MonadPlus Functor and monad classes classes, with Functions some useful Naming conventions operations Basic Monad functions on monads. Generalisations of list functions Conditional execution of monadic Functor expressions Monadic lifting operators and Strict monadic functions monad classes class Functor f where # Source The Functor class is used for types that can be mapped over. Instances of Functor should satisfy the following laws: fmap id == id fmap (f . g) == fmap f . fmap g The instances of Functor for lists, Maybe and IO satisfy these laws. Minimal complete definition fmap Methods fmap :: (a -> b) -> f a -> f b # Source Instances Functor [] # Functor Maybe # Functor IO # Functor V1 # Functor U1 # Functor Par1 # Functor ReadP # Functor ReadPrec # Functor Last # Functor First # Functor Product # Functor Sum # Functor Dual # Functor STM # Functor Handler # Functor ZipList # Functor ArgDescr # Functor OptDescr # Functor ArgOrder # Functor Complex # Functor NonEmpty # Functor Option # Functor Last # Functor First # Functor Max # Functor Min # Functor Identity # Functor ((->) r) # Functor (Either a) # Functor f => Functor (Rec1 f) # Functor (URec Char) # Functor (URec Double) # Functor (URec Float) # Functor (URec Int) # Functor (URec Word) # Functor (URec (Ptr ())) # Functor ((,) a) # Functor (ST s) # Functor (Proxy *) # Arrow a => Functor (ArrowMonad a) # Monad m => Functor (WrappedMonad m) # Functor (ST s) # Functor (Arg a) # Functor (K1 i c) # (Functor g, Functor f) => Functor ((:+:) f g) # (Functor g, Functor f) => Functor ((:*:) f g) # (Functor g, Functor f) => Functor ((:.:) f g) # Functor f => Functor (Alt * f) # Functor (Const * m) # Arrow a => Functor (WrappedArrow a b) # Functor f => Functor (M1 i c f) # (Functor f, Functor g) => Functor (Product * f g) # (Functor f, Functor g) => Functor (Sum * f g) # (Functor f, Functor g) => Functor (Compose * * f g) CPP’18, January 8–9, 2018, Los Angeles, CA, USA Spector-Zabusky, Breitner, Rizkallah, and Weirich # This process makes sense only for inductive data types class Applicative m => Monad m where # Source and total, terminating functions. This is where the semantics The Monad class defines the basic operations over a monad, of lazy and strict evaluation, and hence of Haskell and Coq, a concept from a branch of mathematics known as coincide [8]. However, the payoff is that a successful transla- category theory. From the perspective of a Haskell tion is itself a termination proof, even before other properties programmer, however, it is best to think of a monad as an have been shown. Furthermore, because Coq programs may abstract datatype of actions. Haskell's do expressions be evaluated (within Coq) or compiled (via extraction) these provide a convenient syntax for writing monadic properties apply, not to a formal model of computation, but expressions. to actual runnable code. Instances of Monad should satisfy the following laws: Our overarching goal is to make it easy for a Haskell pro- grammer to produce Coq versions of their programs that are return a >>= k = k a suitable for verification. The Coq rendition should closely m >>= return = m follow the Haskell code – the same names should be used, even within functions; types should be unaltered; abstrac- m >>= (\x -> k x >>= h) = (m >>= k) >>= h tions like type classes and modules should be preserved – so that the programmer obtains not just a black-box that hap- Furthermore, the Monad and Applicative operations pens to do the same thing as the original Haskell program, should relate as follows: but a live Coq version of the input. pure = return Furthermore, the development environment should in- clude as much as possible of total Haskell. In particular, pro- (<*>) = ap grammers should have access to standard libraries and lan- The above laws imply: guage features and face few limitations other than totality. Figure 1. The documentation of the Monad type class lists Also, because programs often change, the generated Coq the threefmap monad f xs laws= xs and >>= thereturn two . laws f relating it to must be usable directly, or with declarative modifications, so Applicative (screenshot).2 that the proofs can evolve with the program. (>>) = (*>) Conversely, an additional application of hs-to-coq is as 2 Reasoning About Haskell Code in Coq a Haskell “rapid prototyping front-end” for Coq. A poten- tial workflow is: (1) implement a program in Haskell first, We present and evaluate our approach to verifying Haskell in order to quickly develop and test it; (2) use hs-to-coq in three examples, all involving pre-existing Haskell code. 1 von 4 to translate it to the Coq world; and (3) extend and verify 2.1 Algebraic Laws the Coq output. This framework allows diverse groups of functional programmers and proof engineers to collaborate; Objective The Functor type class is not the only class with focusing on their areas of expertise. laws. Many Haskell programs feature structures that are not Therefore, in this paper, we describe the design and im- only instances of the Functor class, but also of Applicative plementation of the hs-to-coq tool and
Recommended publications
  • GHC Reading Guide
    GHC Reading Guide - Exploring entrances and mental models to the source code - Takenobu T. Rev. 0.01.1 WIP NOTE: - This is not an official document by the ghc development team. - Please refer to the official documents in detail. - Don't forget “semantics”. It's very important. - This is written for ghc 9.0. Contents Introduction 1. Compiler - Compilation pipeline - Each pipeline stages - Intermediate language syntax - Call graph 2. Runtime system 3. Core libraries Appendix References Introduction Introduction Official resources are here GHC source repository : The GHC Commentary (for developers) : https://gitlab.haskell.org/ghc/ghc https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary GHC Documentation (for users) : * master HEAD https://ghc.gitlab.haskell.org/ghc/doc/ * latest major release https://downloads.haskell.org/~ghc/latest/docs/html/ * version specified https://downloads.haskell.org/~ghc/9.0.1/docs/html/ The User's Guide Core Libraries GHC API Introduction The GHC = Compiler + Runtime System (RTS) + Core Libraries Haskell source (.hs) GHC compiler RuntimeSystem Core Libraries object (.o) (libHsRts.o) (GHC.Base, ...) Linker Executable binary including the RTS (* static link case) Introduction Each division is located in the GHC source tree GHC source repository : https://gitlab.haskell.org/ghc/ghc compiler/ ... compiler sources rts/ ... runtime system sources libraries/ ... core library sources ghc/ ... compiler main includes/ ... include files testsuite/ ... test suites nofib/ ... performance tests mk/ ... build system hadrian/ ... hadrian build system docs/ ... documents : : 1. Compiler 1. Compiler Compilation pipeline 1. compiler The GHC compiler Haskell language GHC compiler Assembly language (native or llvm) 1. compiler GHC compiler comprises pipeline stages GHC compiler Haskell language Parser Renamer Type checker Desugarer Core to Core Core to STG STG to Cmm Assembly language Cmm to Asm (native or llvm) 1.
    [Show full text]
  • NICOLAS WU Department of Computer Science, University of Bristol (E-Mail: [email protected], [email protected])
    Hinze, R., & Wu, N. (2016). Unifying Structured Recursion Schemes. Journal of Functional Programming, 26, [e1]. https://doi.org/10.1017/S0956796815000258 Peer reviewed version Link to published version (if available): 10.1017/S0956796815000258 Link to publication record in Explore Bristol Research PDF-document University of Bristol - Explore Bristol Research General rights This document is made available in accordance with publisher policies. Please cite only the published version using the reference above. Full terms of use are available: http://www.bristol.ac.uk/red/research-policy/pure/user-guides/ebr-terms/ ZU064-05-FPR URS 15 September 2015 9:20 Under consideration for publication in J. Functional Programming 1 Unifying Structured Recursion Schemes An Extended Study RALF HINZE Department of Computer Science, University of Oxford NICOLAS WU Department of Computer Science, University of Bristol (e-mail: [email protected], [email protected]) Abstract Folds and unfolds have been understood as fundamental building blocks for total programming, and have been extended to form an entire zoo of specialised structured recursion schemes. A great number of these schemes were unified by the introduction of adjoint folds, but more exotic beasts such as recursion schemes from comonads proved to be elusive. In this paper, we show how the two canonical derivations of adjunctions from (co)monads yield recursion schemes of significant computational importance: monadic catamorphisms come from the Kleisli construction, and more astonishingly, the elusive recursion schemes from comonads come from the Eilenberg-Moore construction. Thus we demonstrate that adjoint folds are more unifying than previously believed. 1 Introduction Functional programmers have long realised that the full expressive power of recursion is untamable, and so intensive research has been carried out into the identification of an entire zoo of structured recursion schemes that are well-behaved and more amenable to program comprehension and analysis (Meijer et al., 1991).
    [Show full text]
  • Practical Coinduction
    Math. Struct. in Comp. Science: page 1 of 21. c Cambridge University Press 2016 doi:10.1017/S0960129515000493 Practical coinduction DEXTER KOZEN† and ALEXANDRA SILVA‡ †Computer Science, Cornell University, Ithaca, New York 14853-7501, U.S.A. Email: [email protected] ‡Intelligent Systems, Radboud University Nijmegen, Postbus 9010, 6500 GL Nijmegen, the Netherlands Email: [email protected] Received 6 March 2013; revised 17 October 2014 Induction is a well-established proof principle that is taught in most undergraduate programs in mathematics and computer science. In computer science, it is used primarily to reason about inductively defined datatypes such as finite lists, finite trees and the natural numbers. Coinduction is the dual principle that can be used to reason about coinductive datatypes such as infinite streams or trees, but it is not as widespread or as well understood. In this paper, we illustrate through several examples the use of coinduction in informal mathematical arguments. Our aim is to promote the principle as a useful tool for the working mathematician and to bring it to a level of familiarity on par with induction. We show that coinduction is not only about bisimilarity and equality of behaviors, but also applicable to a variety of functions and relations defined on coinductive datatypes. 1. Introduction Perhaps the single most important general proof principle in computer science, and argu- ably in all of mathematics, is induction. There is a valid induction principle corresponding to any well-founded relation, but in computer science, it is most often seen in the form known as structural induction, in which the domain of discourse is an inductively-defined datatype such as finite lists, finite trees, or the natural numbers.
    [Show full text]
  • The Method of Coalgebra: Exercises in Coinduction
    The Method of Coalgebra: exercises in coinduction Jan Rutten CWI & RU [email protected] Draft d.d. 8 July 2018 (comments are welcome) 2 Draft d.d. 8 July 2018 Contents 1 Introduction 7 1.1 The method of coalgebra . .7 1.2 History, roughly and briefly . .7 1.3 Exercises in coinduction . .8 1.4 Enhanced coinduction: algebra and coalgebra combined . .8 1.5 Universal coalgebra . .8 1.6 How to read this book . .8 1.7 Acknowledgements . .9 2 Categories { where coalgebra comes from 11 2.1 The basic definitions . 11 2.2 Category theory in slogans . 12 2.3 Discussion . 16 3 Algebras and coalgebras 19 3.1 Algebras . 19 3.2 Coalgebras . 21 3.3 Discussion . 23 4 Induction and coinduction 25 4.1 Inductive and coinductive definitions . 25 4.2 Proofs by induction and coinduction . 28 4.3 Discussion . 32 5 The method of coalgebra 33 5.1 Basic types of coalgebras . 34 5.2 Coalgebras, systems, automata ::: ....................... 34 6 Dynamical systems 37 6.1 Homomorphisms of dynamical systems . 38 6.2 On the behaviour of dynamical systems . 41 6.3 Discussion . 44 3 4 Draft d.d. 8 July 2018 7 Stream systems 45 7.1 Homomorphisms and bisimulations of stream systems . 46 7.2 The final system of streams . 52 7.3 Defining streams by coinduction . 54 7.4 Coinduction: the bisimulation proof method . 59 7.5 Moessner's Theorem . 66 7.6 The heart of the matter: circularity . 72 7.7 Discussion . 76 8 Deterministic automata 77 8.1 Basic definitions . 78 8.2 Homomorphisms and bisimulations of automata .
    [Show full text]
  • Haskell-Like S-Expression-Based Language Designed for an IDE
    Department of Computing Imperial College London MEng Individual Project Haskell-Like S-Expression-Based Language Designed for an IDE Author: Supervisor: Michal Srb Prof. Susan Eisenbach June 2015 Abstract The state of the programmers’ toolbox is abysmal. Although substantial effort is put into the development of powerful integrated development environments (IDEs), their features often lack capabilities desired by programmers and target primarily classical object oriented languages. This report documents the results of designing a modern programming language with its IDE in mind. We introduce a new statically typed functional language with strong metaprogramming capabilities, targeting JavaScript, the most popular runtime of today; and its accompanying browser-based IDE. We demonstrate the advantages resulting from designing both the language and its IDE at the same time and evaluate the resulting environment by employing it to solve a variety of nontrivial programming tasks. Our results demonstrate that programmers can greatly benefit from the combined application of modern approaches to programming tools. I would like to express my sincere gratitude to Susan, Sophia and Tristan for their invaluable feedback on this project, my family, my parents Michal and Jana and my grandmothers Hana and Jaroslava for supporting me throughout my studies, and to all my friends, especially to Harry whom I met at the interview day and seem to not be able to get rid of ever since. ii Contents Abstract i Contents iii 1 Introduction 1 1.1 Objectives ........................................ 2 1.2 Challenges ........................................ 3 1.3 Contributions ...................................... 4 2 State of the Art 6 2.1 Languages ........................................ 6 2.1.1 Haskell ....................................
    [Show full text]
  • Friends with Benefits: Implementing Corecursion in Foundational
    Friends with Benefits Implementing Corecursion in Foundational Proof Assistants Jasmin Christian Blanchette1;2, Aymeric Bouzy3, Andreas Lochbihler4, Andrei Popescu5;6, and Dmitriy Traytel4 1 Vrije Universiteit Amsterdam, the Netherlands 2 Inria Nancy – Grand Est, Nancy, France 3 Laboratoire d’informatique, École polytechnique, Palaiseau, France 4 Institute of Information Security, Department of Computer Science, ETH Zürich, Switzerland 5 Department of Computer Science, Middlesex University London, UK 6 Institute of Mathematics Simion Stoilow of the Romanian Academy, Bucharest, Romania Abstract. We introduce AmiCo, a tool that extends a proof assistant, Isabelle/ HOL, with flexible function definitions well beyond primitive corecursion. All definitions are certified by the assistant’s inference kernel to guard against in- consistencies. A central notion is that of friends: functions that preserve the pro- ductivity of their arguments and that are allowed in corecursive call contexts. As new friends are registered, corecursion benefits by becoming more expressive. We describe this process and its implementation, from the user’s specification to the synthesis of a higher-order definition to the registration of a friend. We show some substantial case studies where our approach makes a difference. 1 Introduction Codatatypes and corecursion are emerging as a major methodology for programming with infinite objects. Unlike in traditional lazy functional programming, codatatypes support total (co)programming [1, 8, 30, 68], where the defined functions have a simple set-theoretic semantics and productivity is guaranteed. The proof assistants Agda [19], Coq [12], and Matita [7] have been supporting this methodology for years. By contrast, proof assistants based on higher-order logic (HOL), such as HOL4 [64], HOL Light [32], and Isabelle/HOL [56], have traditionally provided only datatypes.
    [Show full text]
  • A Formal Methodology for Deriving Purely Functional Programs from Z Specifications Via the Intermediate Specification Language Funz
    Louisiana State University LSU Digital Commons LSU Historical Dissertations and Theses Graduate School 1995 A Formal Methodology for Deriving Purely Functional Programs From Z Specifications via the Intermediate Specification Language FunZ. Linda Bostwick Sherrell Louisiana State University and Agricultural & Mechanical College Follow this and additional works at: https://digitalcommons.lsu.edu/gradschool_disstheses Recommended Citation Sherrell, Linda Bostwick, "A Formal Methodology for Deriving Purely Functional Programs From Z Specifications via the Intermediate Specification Language FunZ." (1995). LSU Historical Dissertations and Theses. 5981. https://digitalcommons.lsu.edu/gradschool_disstheses/5981 This Dissertation is brought to you for free and open access by the Graduate School at LSU Digital Commons. It has been accepted for inclusion in LSU Historical Dissertations and Theses by an authorized administrator of LSU Digital Commons. For more information, please contact [email protected]. INFORMATION TO USERS This manuscript has been reproduced from the microfilm master. UMI films the text directly from the original or copy submitted. Thus, some thesis and dissertation copies are in typewriter face, while others may be from any type of computer printer. H ie quality of this reproduction is dependent upon the quality of the copy submitted. Broken or indistinct print, colored or poor quality illustrations and photographs, print bleedthrough, substandardm argins, and improper alignment can adversely affect reproduction. In the unlikely, event that the author did not send UMI a complete manuscript and there are missing pages, these will be noted. Also, if unauthorized copyright material had to be removed, a note will indicate the deletion. Oversize materials (e.g., maps, drawings, charts) are reproduced by sectioning the original, beginning at the upper left-hand comer and continuing from left to right in equal sections with small overlaps.
    [Show full text]
  • The Logic of Demand in Haskell
    Under consideration for publication in J. Functional Programming 1 The Logic of Demand in Haskell WILLIAM L. HARRISON Department of Computer Science University of Missouri Columbia, Missouri RICHARD B. KIEBURTZ Pacific Software Research Center OGI School of Science & Engineering Oregon Health & Science University Abstract Haskell is a functional programming language whose evaluation is lazy by default. However, Haskell also provides pattern matching facilities which add a modicum of eagerness to its otherwise lazy default evaluation. This mixed or “non-strict” semantics can be quite difficult to reason with. This paper introduces a programming logic, P-logic, which neatly formalizes the mixed evaluation in Haskell pattern-matching as a logic, thereby simplifying the task of specifying and verifying Haskell programs. In P-logic, aspects of demand are reflected or represented within both the predicate language and its model theory, allowing for expressive and comprehensible program verification. 1 Introduction Although Haskell is known as a lazy functional language because of its default eval- uation strategy, it contains a number of language constructs that force exceptions to that strategy. Among these features are pattern-matching, data type strictness annotations and the seq primitive. The semantics of pattern-matching are further enriched by irrefutable pattern annotations, which may be embedded within pat- terns. The interaction between Haskell’s default lazy evaluation and its pattern- matching is surprisingly complicated. Although it offers the programmer a facility for fine control of demand (Harrison et al., 2002), it is perhaps the aspect of the Haskell language least well understood by its community of users. In this paper, we characterize the control of demand first in a denotational semantics and then in a verification logic called “P-logic”.
    [Show full text]
  • Some New Approaches in Functional Programming Using Algebras and Coalgebras
    Available online at www.sciencedirect.com Electronic Notes in Theoretical Computer Science 279 (3) (2011) 41–62 www.elsevier.com/locate/entcs Some New Approaches in Functional Programming Using Algebras and Coalgebras Viliam Slodiˇc´ak1,2 Pavol Macko3 Department of Computers and Informatics Technical University of Koˇsice Koˇsice, Slovak Republic Abstract In our paper we deal with the expressing of recursion and corecursion in functional programming. We discuss about the morphisms which express the recursion or corecursion, respectively. Here we consider especially the catamorphisms, anamorphisms and their composition called the hylomorphisms. The main essence of this work is to describe a new method of programming the function for calculating the factorial by using hylomorphism. We show that using of hylomorphism is an alternative method for the computation of factorial to recursive methods programmed classically. Our new method we describe in action semantics which is a new formal method for the program description. Keywords: Recursion, duality, hylomorphism, algebra, recursive coalgebras, action semantics. 1 Introduction Recursion is a very useful tool in modern programming languages, in particular when we deal with inductive data structures such as lists, trees, etc. [9]. The theory of recursive functions was developed by Kurt G¨odeland Stephen Kleene in the 1930s. Now the recursion has the great importance in mathematics and in computer science. The recursion method presents very interesting solution of many computational algorithms. It is an inherent part of functional programming. On the other hand, the dual method called corecursion brings the new opportunities in programming. In section 2 we formulate basic notions from the category the- ory, the mathematical tool which importance for theoretical informatics growth in last decade.
    [Show full text]
  • Corecursive Algebras: a Study of General Structured Corecursion (Extended Abstract)
    Corecursive Algebras: A Study of General Structured Corecursion (Extended Abstract) Venanzio Capretta1, Tarmo Uustalu2, and Varmo Vene3 1 Institute for Computer and Information Science, Radboud University Nijmegen 2 Institute of Cybernetics, Tallinn University of Technology 3 Department of Computer Science, University of Tartu Abstract. We study general structured corecursion, dualizing the work of Osius, Taylor, and others on general structured recursion. We call an algebra of a functor corecursive if it supports general structured corecur- sion: there is a unique map to it from any coalgebra of the same functor. The concept of antifounded algebra is a statement of the bisimulation principle. We show that it is independent from corecursiveness: Neither condition implies the other. Finally, we call an algebra focusing if its codomain can be reconstructed by iterating structural refinement. This is the strongest condition and implies all the others. 1 Introduction A line of research started by Osius and Taylor studies the categorical foundations of general structured recursion. A recursive coalgebra (RCA) is a coalgebra of a functor F with a unique coalgebra-to-algebra morphism to any F -algebra. In other words, it is an algebra guaranteeing unique solvability of any structured recursive diagram. The notion was introduced by Osius [Osi74] (it was also of interest to Eppendahl [Epp99]; we studied construction of recursive coalgebras from coalgebras known to be recursive with the help of distributive laws of functors over comonads [CUV06]). Taylor introduced the notion of wellfounded coalgebra (WFCA) and proved that, in a Set-like category, it is equivalent to RCA [Tay96a,Tay96b],[Tay99, Ch.
    [Show full text]
  • Corecursion in Session-Typed Processes
    Corecursion in Session-Typed Processes Bernardo Toninho∗y, Lu´ıs Caires∗ and Frank Pfenningy ∗CITI and FCT - Universidade Nova de Lisboa yCarnegie Mellon University Abstract—Session types are widely accepted as a useful expres- has sparked a renewed interest in session types and their foun- sive discipline for structuring communications in concurrent and dations [5], and in the idea of exploiting logically motivated distributed systems. In order to express infinitely unbounded approaches for providing powerful reasoning techniques about sessions, as required to model the behaviour of realistic dis- tributed systems, session typed languages often introduce general concurrent and distributed systems. This line of work has recursion operators at both the program and the type level. addressed concepts such as value-dependent types [6], proof- Unfortunately, general recursion, in particular when combined carrying code [7] behavioural polymorphism [8], and higher- with name passing and mobility, may easily introduce undesirable order computation [9], approaching a general type theory for divergence, e.g., infinite unobservable reduction sequences. session-based concurrency, with strong guarantees by virtue In this paper we address, by means of typing, the challenge of ensuring non-divergence in a session-typed π-calculus with of typing such as deadlock freedom and session fidelity. general (co)recursion, while still allowing interesting infinite Although in the untyped case infinite behavior is potentially behaviours to be definable, as necessary to model realistic open encodable using replication in the π-calculus, to express process networks and distributed systems. Our approach builds infinitely unbounded session exchanges, as required to model on a Curry-Howard correspondence between our type system the behaviour of realistic distributed systems, session typed and a standard system of linear logic extended with co-inductive types, for which our non-divergence property implies consistency.
    [Show full text]
  • Functional Baby Talk: Analysis of Code Fragments from Novice Haskell Programmers
    Functional Baby Talk: Analysis of Code Fragments from Novice Haskell Programmers Jeremy Singer and Blair Archibald School of Computing Science University of Glasgow UK [email protected] [email protected] What kinds of mistakes are made by novice Haskell developers, as they learn about functional pro- gramming? Is it possible to analyze these errors in order to improve the pedagogy of Haskell? In 2016, we delivered a massive open online course which featured an interactive code evaluation en- vironment. We captured and analyzed 161K interactions from learners. We report typical novice developer behavior; for instance, the mean time spent on an interactive tutorial is around eight min- utes. Although our environment was restricted, we gain some understanding of Haskell novice er- rors. Parenthesis mismatches, lexical scoping errors and do block misunderstandings are common. Finally, we make recommendations about how such beginner code evaluation environments might be enhanced. 1 Introduction The Haskell programming language [14] has acquired a reputation for being difficult to learn. In his presentation on the origins of Haskell [23] Peyton Jones notes that, according to various programming language popularity metrics, Haskell is much more frequently discussed than it is used for software implementation. The xkcd comic series features a sarcastic strip on Haskell’s side-effect free property [21]. Haskell code is free from side-effects ‘because no-one will ever run it.’ In 2016, we ran the first instance of a massive open online course (MOOC) at Glasgow, providing an introduction to functional programming in Haskell. We received many items of learner feedback that indicated difficulty in learning Haskell.
    [Show full text]