VU Logic and Computation – P

Total Page:16

File Type:pdf, Size:1020Kb

VU Logic and Computation – P VU Logic and Computation Agata Ciabattoni Institute fur¨ Computersprachen, Theory and Logic group [email protected] VU Logic and Computation – p. 1 Lection 4 – Computability Theory • Combinatory Logic • Recursive functions • (Hints on the) Equivalence between λ-calculus, recursive functions and TM • Computable and non computable functions VU Logic and Computation – p. 2 Combinatory Logic VU Logic and Computation – p. 3 Combinatory Logic: Motivation Example: commutative law of addition in arithmetic (∀xy) x + y = y + x VU Logic and Computation – p. 4 Combinatory Logic: Motivation Example: commutative law of addition in arithmetic (∀xy) x + y = y + x it can be expressed without the bound variables x and y: • first define A(x,y) = x + y (for all x and y) • then introduce an operator C defined by (Cf)(x,y) = f(y,x) (for all f,x and y) • then the commutative law becomes simply A = CA VU Logic and Computation – p. 4 Combinatory Logic: Motivation Example: commutative law of addition in arithmetic (∀xy) x + y = y + x it can be expressed without the bound variables x and y: • first define A(x,y) = x + y (for all x and y) • then introduce an operator C defined by (Cf)(x,y) = f(y,x) (for all f,x and y) • then the commutative law becomes simply A = CA C is called combinator VU Logic and Computation – p. 4 Combinatory Logic • only two constants S and K • only application (MN) VU Logic and Computation – p. 5 Combinatory Logic • only two constants S and K • only application (MN) (KMN) → M (SMNP ) → (MP )(NP ) with M,N and P terms of CL (combinators). VU Logic and Computation – p. 5 Equivalence with λ calculus K and S are expressible in λ calculus VU Logic and Computation – p. 6 Equivalence with λ calculus K and S are expressible in λ calculus (Vice versa) For each combinator M, there exist λ∗x.M which behaves as the λ abstraction, that is ∗ (λ x.MN) → M[N/x] Proof: We define λ∗x.M by structural induction: If M = x, then λ∗x.x = I =(SKK) If M does not contain x, then λ∗x.M =(KM) If M =(P Q), then λ∗x.(P Q)=(Sλ∗x.P λ∗x.Q) VU Logic and Computation – p. 6 Recursive Functions • An abstract description of computable functions – Gödel and Kleene (1936) • useful to study recursive programs VU Logic and Computation – p. 7 Recursive Functions • An abstract description of computable functions – Gödel and Kleene (1936) • useful to study recursive programs They form the smallest collection of partial functions containing some basic functions and closed under some fundamental operations for forming new functions from old – composition, primitive recursion and minimization. VU Logic and Computation – p. 7 Basic Functions • n n Projection functions, proji : N →N : n proji (x1,...xn) = xi • Constant funtions with value 0, zeron : N n →N : n zero (x1,...xn) = 0 • Successor function, succ : N →N : succ(x) = x + 1 VU Logic and Computation – p. 8 Composition n m Given f : N →N and g1,...gn : N →N , their composition is m the function f ◦ [g1,...gn] ∈N →N such that f ◦ [g1,...gn](x1,...xm) ≃ f(g1(x1,...xm),...gn(x1,...xm)) where ≃ is the equivalence of possibly undefined expressions VU Logic and Computation – p. 9 Recursion A function f is recursive when the value of f on some arguments depends on the value of f on "simpler" arguments. VU Logic and Computation – p. 10 Recursion A function f is recursive when the value of f on some arguments depends on the value of f on "simpler" arguments. • f1(0) = 0 f1(x + 1) = f1(x)+(x + 1) • f2(0) = 1 f2(x + 1) = (x + 1)f2(x) VU Logic and Computation – p. 10 Primitive Recursive Functions k Is the class of functions containing zero, succ and proji , closed under compositions and primitive recursion: Let g be a k-ary PRF and h be a k + 2-ary PRF. Then the k + 1-ary function f: f(0, x) = g(x) f(y + 1, x) = h(y,f(y, x), x) is PR. VU Logic and Computation – p. 11 PRF – Example 1 Addition: 1 sum(0,x) = proj1 (x) sum(y + 1,x) = h(y, sum(y,x),x) where 3 h := λxyz.succ(proj2 (x,y,z)) VU Logic and Computation – p. 12 PRF – Example 2 Product P (0,x) = zero1(x) P (y + 1,x) = h′(y, P (y,x),x) where ′ 3 3 h := λxyz.sum(proj2 (x,y,z),proj3 (x,y,z)) VU Logic and Computation – p. 13 Elementary Functions Is the subclass of primitive recursive functions containing k zero, succ, subtr and proji , closed under compositions and • m bounded summation f(m, x1,...,xn) = Pi=0 g(i, x1,...,xn) • m bounded product f(m, x1,...,xn) = Qi=0 g(i, x1,...,xn) (where g is elementary recursive) VU Logic and Computation – p. 14 Primitive Recursive Functions k Is the class of functions containing zero, succ and proji , closed under compositions and primitive recursion: f(0, x) = g(x) f(y + 1, x) = h(y,f(y, x), x) • total functions • all total computable function? VU Logic and Computation – p. 15 Ackermann Function f(0, 0,y) = y f(0,x + 1,y) = f(0,x,y) + 1 f(1, 0,y) = 0 f(z + 2, 0,y) = 1 f(z + 1,x + 1,y) = f(z,f(z + 1,x,y),y)) • f is computable • f grows faster than any PRF! (i.e., for any PRF F, there is an n such that f(n,x,y) >F (x,y)) VU Logic and Computation – p. 16 Extending the PRF g(x) = min y such that f(x,y) = 0 is g computable, if so is f? VU Logic and Computation – p. 17 Recursive Functions Is the smallest collection of functions containing all primitive k recursive functions (zero, succ and proji , closed under compositions and primitive recursion) and closed under minimalization: g(x) = µy(f(x,y) = 0) = min y such that f(x,y) = 0 and (f(x, z) ↓ for all z ≤ y and f(x, z) =6 0) ↑ otherwise Theorem If f is computable, so is g. VU Logic and Computation – p. 18 Example x D(x,y) = y if ∃z such that yz = x, and it is ↑ otherwise. VU Logic and Computation – p. 19 Example x D(x,y) = y if ∃z such that yz = x, and it is ↑ otherwise. D(x,y) := µz[eq(yz,x) = 0] where • Pred(0) = 0, and Pred(succ(x)) = x • x −⋆ 0 = x and x −⋆ succ(y) = Pred(x −⋆ y) • eq(x,y) = x −⋆ y + y −⋆ x VU Logic and Computation – p. 19 Church-Turing Thesis Formal notions appeared, starting in 1936: λ-calculus of Alonzo Church Turing machines of Alan Turing Recursive functions of Gödel and Kleene . These definitions look very different, but are provably equivalent. VU Logic and Computation – p. 20 Model of computations: equivalences • Recursive functions • λ-calculus • Combinatory logic • Turing machines • ... VU Logic and Computation – p. 21 Encoding of recursive functions in λ calculus Definition λ-definable functions f : N n →N is λ-definable if there is a closed λ-term F that n represents it: that is for all (x1,...xn) ∈N and y ∈N β • if f(x1,...xn) = y then Fx1 ...xn = y • if f(x1,...xn) ↑, then Fx1 ...xn has no β-nf VU Logic and Computation – p. 22 Church’s numerals n := λxy.x(x(. (x y) . ) | n times{z } Example 0 = λxy.y 1 = λxy.xy 2 = λxy.x(xy) (nM)N =β M(M(. (M N) . ) | n times{z } examples of functions on the blackboard ... VU Logic and Computation – p. 23 λ calculus and recursion Example (factorial function fact) λn. if n = 0 then 0 else n · ??(n − 1) VU Logic and Computation – p. 24 λ calculus and recursion Example (factorial function fact) λn. if n = 0 then 0 else n · ??(n − 1) Fixed point of a function f is a value x for which fx = x VU Logic and Computation – p. 24 λ calculus and recursion Example (factorial function fact) λn. if n = 0 then 0 else n · ??(n − 1) Fixed point of a function f is a value x for which fx = x Proposition Every λ term has a fixpoint, i.e. a term θ s.t. for all M: θM =β M(θM) 1. N := λf.λn. if n = 0 then 1 else n · f(n − 1) 2. fact := θN VU Logic and Computation – p. 24 Fixed Point and µ-recursion Fixed Point Is a term θ s.t. for all M: θM = M(θM). µ-recursion g(x) = µy(f(x,y) = 0) = min y such that f(x,y) = 0 and (f(x, z) ↓ for all z ≤ y and f(x, z) =6 0) ↑ otherwise VU Logic and Computation – p. 25 λ-definable ⇒ Turing Computable Theorem A λ-definable function is Turing Computable (T-Computable). VU Logic and Computation – p. 26 λ-definable ⇒ Turing Computable Theorem A λ-definable function is Turing Computable (T-Computable). To show this one can • code λ-terms as numbers (ensuring that operations for constructing and deconstructing terms are given by T-computable functions on codes) • write a T-interpreter for β-reductions VU Logic and Computation – p. 26 T-Computable ⇒ Recursive function Theorem A Turing Computable function is definable as a recursive function. VU Logic and Computation – p. 27 T-Computable ⇒ Recursive function Theorem A Turing Computable function is definable as a recursive function. To show this one can • code tape configurations and states of a Turing machine during a computation by natural numbers • the operation of the machine is represented by recursive functions of these numbers VU Logic and Computation – p.
Recommended publications
  • The Lambda Calculus Is Algebraic
    Under consideration for publication in J. Functional Programming 1 2 P. Selinger point of view. We suggest another way of looking at the problem, which yields a sense in which the lambda calculus is equivalent to an algebraic theory. The Lambda Calculus is Algebraic The basic observation is that the failure of the ξ-rule is not a deficiency of the lambda calculus itself, nor of combinatory algebras, but rather it is an artifact of the way free variables are interpreted in a model. Under the usual interpretation, free variables are in- PETER SELINGER terpreted as elements of a lambda algebra A. Thus, an equation M = N between terms Department of Mathematics and Statistics University of Ottawa, Ottawa, Ontario K1N 6N5, Canada is said to be satisfied if it holds whenever the free variables of M and N are replaced by (e-mail: [email protected]) elements of A. We call this the local interpretation. We suggest a different interpretation, called the absolute interpretation, under which free variables are interpreted as indetermi- nates. Let A[x1 ...xn] be the lambda algebra obtained from A by freely adjoining elements Abstract x1 ...xn. Under the absolute interpretation, an equation M = N is said to be satisfied if it holds in A[x1 ...xn]. This paper serves as a self-contained, tutorial introduction to combinatory models of the untyped The fundamental observationof this paper is that the two interpretations do not coincide, lambda calculus. We focus particularly on the interpretation of free variables. We argue that free and that the absolute interpretation satisfies all rules of the lambda calculus, including the variables should not be interpreted as elements in a model, as is usually done, but as indeterminates.
    [Show full text]
  • Deriving Logical Relations from Interpretations of Predicate Logic
    Replace this file with prentcsmacro.sty for your meeting, or with entcsmacro.sty for your meeting. Both can be found through links on the ENTCS Web Page. Deriving Logical Relations from Interpretations of Predicate Logic Claudio Hermida1 Uday S. Reddy2 University of Birmingham Edmund P. Robinson3;4 Queen Mary, University of London Abstract This paper extends the results of Hermida's thesis about logical predicates to more general logical relations and a wider collection of types. The extension of type constructors from types to logical relations is derived from an interpretation of those constructors on a model of predicate logic. This is then further extended to n-ary relations by pullback. Hermida's theory shows how right adjoints in the category of fibrations are composed from a combination of Cartesian lifting and a local adjunction. This result is generalised to make it more applicable to left adjoints, and then shown to be stable under pullback, deriving an account of n-ary relations from standard predicate logic. A brief discussion of lifting monads to predicates includes the existence of an initial such lifting, generalising existing results. Keywords: logical relations, fibrations, categorical type theory, monadic types 1 Introduction The purpose of this paper is to illustrate a link between logical relations and predicate logics. We begin by revisiting the conditions under which the predicates in a predicate logic for reasoning about a type theory can be shown to carry the structure of that type theory. We then show that similar structure on binary and more generally n-ary relations can be derived from that on unary predicates.
    [Show full text]
  • The Proper Treatment of Variables in Predicate Logic
    The Proper Treatment of Variables in Predicate Logic Kai F. Wehmeier University of California, Irvine Abstract Bertrand Russell (1903, x93) observed that “the variable is a very complicated logi- cal entity, by no means easy to analyze correctly”. This assessment is borne out by the fact that even now we have no fully satisfactory understanding of the role of variables in a compositional semantics for first-order logic. In standard Tarskian semantics, variables are treated as meaning-bearing entities; moreover, they serve as the basic building blocks of all meanings, which are constructed out of variable assignments. But this has disquieting consequences, including Fine’s antinomy of the variable and an undue dependence of meanings on language (representation- alism). Here I develop an alternative, Fregean version of predicate logic that uses the traditional quantifier–variable apparatus for the expression of generality, pos- sesses a fully compositional, non-representational semantics, and is not subject to the antinomy of the variable. The advantages of Fregean over Tarskian predicate logic are due to the former’s treating variables not as meaningful lexical items, but as mere marks of punctuation, similar to parentheses. I submit that this is indeed how the variables of predicate logic should be construed. 1 1 Introduction In standard, Tarski-style syntax for first-order logic, atomic formulas are constructed from predicate symbols and an appropriate number of variables and names. Truth- functional connectives can be used to form new formulas out of ones already con- structed. From any formula already constructed, and any individual variable, a new formula can be obtained by first writing a quantifier symbol, appending the chosen variable, and then appending the original formula.
    [Show full text]
  • Exceptionally Monadic Error Handling
    Exceptionally Monadic Error Handling Looking at bind and squinting really hard Jan Malakhovski∗ IRIT, University of Toulouse-3 and ITMO University February 2014 - October 2018 Abstract We notice that the type of catch :: c a -> (e -> c a) -> c a operator is a special case of monadic bind operator (>>=) :: m a -> (a -> m b) -> m b, the semantics (surprisingly) matches, and this observation has many interesting consequences. For instance, the reader is probably aware that the monadic essence of the (>>=) operator of the error monad λA.E ∨ A is to behave like identity monad for "normal" values and to stop on "errors". The unappreciated fact is that handling of said "errors" with a catch operator of the "flipped" "conjoined" error monad λE.E ∨ A is, too, a monadic computation that treats still unhandled "errors" as "normal" values and stops when an "error" is finally handled. We show that for an appropriately indexed type of computations such a "conjoined" struc- ture naturally follows from the conventional operational semantics of throw and catch operators. Consequently, we show that this structure uniformly generalizes all conventional monadic error handling mechanisms we are aware of. We also demonstrate several more interesting instances of this structure of which at least bi-indexed monadic parser combinators and conventional exceptions implemented via continuations have immediate practical applications. Finally, we notice that these observations provide surprising perspectives on error handling in general and point to a largely unexplored trail in programming language design space. Contents 1 Extended Abstract 3 2 Preliminaries 4 3 Introduction 5 4 Not a Tutorial: Side A 7 arXiv:1810.13430v3 [cs.PL] 30 Jan 2019 4.1 Before-Monadic.................................
    [Show full text]
  • Two Lectures on Constructive Type Theory
    Two Lectures on Constructive Type Theory Robert L. Constable July 20, 2015 Abstract Main Goal: One goal of these two lectures is to explain how important ideas and problems from computer science and mathematics can be expressed well in constructive type theory and how proof assistants for type theory help us solve them. Another goal is to note examples of abstract mathematical ideas currently not expressed well enough in type theory. The two lec- tures will address the following three specific questions related to this goal. Three Questions: One, what are the most important foundational ideas in computer science and mathematics that are expressed well in constructive type theory, and what concepts are more difficult to express? Two, how can proof assistants for type theory have a large impact on research and education, specifically in computer science, mathematics, and beyond? Three, what key ideas from type theory are students missing if they know only one of the modern type theories? The lectures are intended to complement the hands-on Nuprl tutorials by Dr. Mark Bickford that will introduce new topics as well as address these questions. The lectures refer to recent educational material posted on the PRL project web page, www.nuprl.org, especially the on-line article Logical Investigations, July 2014 on the front page of the web cite. Background: Decades of experience using proof assistants for constructive type theories, such as Agda, Coq, and Nuprl, have brought type theory ever deeper into computer science research and education. New type theories implemented by proof assistants are being developed. More- over, mathematicians are showing interest in enriching these theories to make them a more suitable foundation for mathematics.
    [Show full text]
  • Code-Free Recursion & Realizability
    Code-free recursion & realizability Eric Faber Universiteit Utrecht February 24, 2014 Outline 1 History Combinatory Logic Computability Theory Motivation 2 Partial combinatory algebras PCAs are very rich PCAs allow for Abstract Recursion Theory 3 Realizability Toposes From Categories of Assemblies . to Realizability Toposes Morphisms Subtoposes Eric Faber ( Universiteit Utrecht ) Code-free recursion & realizability February 24, 2014 2 / 30 History Combinatory Logic Combinatory Logic • Combinatory logic was founded by Moses Schönfinkel in his article “Über die Bausteine der mathematischen Logik” in 1924. • Intended as a pre-logic that would solve foundational issues that arise from the use of variables by eliminating them. • Further development was mostly due to Haskell Curry in the 50s, after which combinatory logic regained interest in theoretical computer science Moses Schönfinkel Haskell Curry Eric Faber ( Universiteit Utrecht ) Code-free recursion & realizability February 24, 2014 3 / 30 History Computability Theory Computability Theory • Founded in 1936 by work of Alan Turing, Alonzo Church, Stephen Kleene and Emil Post • Mathematical rigorous definition of a computation • First results on undecidability Turing Church Kleene Post Eric Faber ( Universiteit Utrecht ) Code-free recursion & realizability February 24, 2014 4 / 30 History Computability Theory The Effective Topos • In 1982, Martin Hyland discovered the “Effective Topos” • From the viewpoint of a Topos as a “constructive universe”, the Effective Topos is an effective universe. • The internal first-order logic of the Effective Topos coincides with Kleene’s notion of realizability Martin Hyland Eric Faber ( Universiteit Utrecht ) Code-free recursion & realizability February 24, 2014 5 / 30 History Motivation Why Study PCAs and Realizability Toposes? • PCAs give rise to a lot of interpretations of constructive proofs • Realizability Toposes give higher-order interpretations of this logic and help understand them • Applications in Computer Science (e.g.
    [Show full text]
  • Representation of Compositional Relational Programs
    Representation of Compositional Relational Programs Representation of Compositional Relational Programs Görkem Paçacı Dissertation presented at Uppsala University to be publicly examined in Lecture hall 2, Ekonomikum, Uppsala, Friday, 28 April 2017 at 13:00 for the degree of Doctor of Philosophy. The examination will be conducted in English. Faculty examiner: Professor Alberto Pettorossi (University of Rome Tor Vergata). Abstract Paçacı, G. 2017. Representation of Compositional Relational Programs. 216 pp. Uppsala: Department of Informatics and Media, Uppsala University. ISBN 978-91-506-2621-6. Usability aspects of programming languages are often overlooked, yet have a substantial effect on programmer productivity. These issues are even more acute in the field of Inductive Synthesis, where programs are automatically generated from sample expected input and output data, and the programmer needs to be able to comprehend, and confirm or reject the suggested programs. A promising method of Inductive Synthesis, CombInduce, which is particularly suitable for synthesizing recursive programs, is a candidate for improvements in usability as the target language Combilog is not user-friendly. The method requires the target language to be strictly compositional, hence devoid of variables, yet have the expressiveness of definite clause programs. This sets up a challenging problem for establishing a user-friendly but equally expressive target language. Alternatives to Combilog, such as Quine's Predicate-functor Logic and Schönfinkel and Curry's Combinatory Logic also do not offer a practical notation: finding a more usable representation is imperative. This thesis presents two distinct approaches towards more convenient representations which still maintain compositionality. The first is Visual Combilog (VC), a system for visualizing Combilog programs.
    [Show full text]
  • Lukasz LACHOWSKI on the COMPLEXITY of the STANDARD TRANSLATION of LAMBDA CALCULUS INTO COMBINATORY LOGIC
    REPORTS ON MATHEMATICAL LOGIC 53 (2018), 19–42 doi: 10.4467/20842589RM.18.002.8835 Lukasz LACHOWSKI ON THE COMPLEXITY OF THE STANDARD TRANSLATION OF LAMBDA CALCULUS INTO COMBINATORY LOGIC A b s t r a c t. We investigate the complexity of the standard translation of lambda calculus into combinatory logic. The main result shows that the asymptotic growth rate of the size of a trans- lated term is Θ(n3) in worst-case, where n denotes the size of the lambda term. .1 Introduction Both lambda calculus ([Chu36]) and combinatory logic ([Cur30]) are Turing- complete models of computation. As such, lambda calculus serves as a the- Received 8 June 2017 This work was partially supported by the grant 2013/11/B/ST6/00975 funded by the Pol- ish National Science Center. Keywords and phrases: combinatory logic, lambda calculus, complexity analysis, func- tional programming. AMS subject classification: 03B40, 68Q25, 68N18. 20 LUKASZ LACHOWSKI oretical basis for many functional programming languages, e.g. Haskell and SML. Evaluating expressions in lambda calculus is not easy since semantics of the substitution must be defined carefully to avoid problems with vari- ables binding. One of the motivations for introducing combinatory logic was to eliminate the notion of bound variables from logical formulas and to simplify the definition of substitution. Thereby, compared to lambda calcu- lus, combinatory logic is simpler in terms of computational interpretations. In the definition of combinatory logic we use only two combinators, namely S and K. Together with the notion of reduction, it is sufficient to define any recursive function in this model.
    [Show full text]
  • Lambda-Calculus : from Logic to Computation
    Introduction Context : development of functional systems Age 1 : Lambda-formalism in a system of logic Age 2 : Constitution of lambda-calculus Age 3 : Introduction of types Conclusions Lambda-Calculus : from logic to computation Wendy Hammache IRPhiL, Université Jean Moulin Lyon 3 PROGRAMme Autumn workshop: formalisms at the interface with machines, languages and systems, Bertinoro October 17, 2018 Wendy Hammache Lambda-Calculus : from logic to computation 1 / 25 Introduction Context : development of functional systems Age 1 : Lambda-formalism in a system of logic Topic of the talk Age 2 : Constitution of lambda-calculus Outline Age 3 : Introduction of types Conclusions Lambda-calculus Nowadays we say about lambda-calculus : It is the first programming language It is the formalism underlying every functional programming language It embodies the formalism to write every program we can code with traditional programming languages Wendy Hammache Lambda-Calculus : from logic to computation 2 / 25 Introduction Context : development of functional systems Age 1 : Lambda-formalism in a system of logic Topic of the talk Age 2 : Constitution of lambda-calculus Outline Age 3 : Introduction of types Conclusions Lambda-calculus Why would we want to create a programming language ? as computers did not exist yet What could be the resaons to create a language such as a programming one ? Motivations ? Usage ? Wendy Hammache Lambda-Calculus : from logic to computation 3 / 25 Introduction Context : development of functional systems Age 1 : Lambda-formalism
    [Show full text]
  • Categorical Combinators
    INFORMATION AND CONTROL 69, 188-254 (1986) Categorical Combinators P.-L. CURIEN CNRS-UniversitO Paris VII, LITP, Tour 55-56 ler dtage, 3 Place Jussieu, 75221 Paris Cedex 05, France Our main aim is to present the connection between 2-calculus and Cartesian closed categories both in an untyped and purely syntactic setting. More specifically we establish a syntactic equivalence theorem between what we call categorical com- binatory logic and j--calculus with explicit products and projections, with fl and q-rules as well as with surjective pairing. "Combinatory logic" is of course inspired by Curry's combinatory logic, based on the well-known S, K,/. Our combinatory logic is "categorical" because its combinators and rules are obtained by extracting untyped information from Cartesian closed categories (looking at arrows only, thus forgetting about objects). Compiling J.-calculus into these combinators happens to be natural and provokes only n log n code expansion. Moreover categorical com- binatory logic is entirely faithful to /~-reduction where combinatory logic needs additional rather complex and unnatural axioms to be. The connection easily extends to the corresponding typed calculi, where typed categorical combinatory logic is a free Cartesian closed category where the notion of terminal object is replaced by the explicit manipulation of applying (a function to its argument) and coupling (arguments to build datas in products). Our syntactic equivalences induce equivalences at the model level. The paper is intended as a mathematical foun- dation for developing implementations of functional programming languages based on a "categorical abstract machine," as developed in a companion paper (Cousineau, Curien, and Mauny, in "Proceedings, ACM Conf.
    [Show full text]
  • Functional Programming with Overloading and Higher-Order Polymorphism
    Functional Programming with Overloading and Higher-Order Polymorphism Mark P. Jones Department of Computer Science, University of Nottingham, University Park, Nottingham NG7 2RD, UK. Abstract. The Hindley/Milner type system has been widely adopted as a basis for statically typed functional languages. One of the main reasons for this is that it provides an elegant compromise between flexibility, al- lowing a single value to be used in different ways, and practicality, freeing the programmer from the need to supply explicit type information. Focusing on practical applications rather than implementation or theo- retical details, these notes examine a range of extensions that provide more flexible type systems while retaining many of the properties that have made the original Hindley/Milner system so popular. The topics discussed, some old, but most quite recent, include higher-order poly- morphism and type and constructor class overloading. Particular em- phasis is placed on the use of these features to promote modularity and reusability. 1 Introduction The Hindley/Milner type system [6, 19, 3], hereafter referred to as HM, repre- sents a significant and highly influential step in the development of type systems for functional programming languages. In our opinion, the main reason for this is that it combines the following features in a single framework: – Type security: soundness results guarantee that well-typed programs can- not ‘go wrong’. This should be compared with the situation in dynamically typed languages like Scheme where run-time tests are often required to check that appropriate types of value are used in a particular context, and the ex- ecution of a program may terminate if these tests fail.
    [Show full text]
  • The Monad.Reader Issue 17 by Douglas M
    The Monad.Reader Issue 17 by Douglas M. Auclair [email protected] and Neil Brown [email protected] and Petr Pudl´ak [email protected] January 9, 2011 Brent Yorgey, editor. Contents Brent Yorgey Editorial3 Douglas M. Auclair List Leads Off with the Letter λ 5 Neil Brown The InterleaveT Abstraction: Alternative with Flexible Ordering 13 Petr Pudl´ak The Reader Monad and Abstraction Elimination 35 2 Editorial by Brent Yorgey [email protected] You may have noticed this edition of The Monad.Reader is rather late. This is because for the past eight months I have been the prisoner of giant, evil, imperative- programming-obsessed naked mole rats. I have managed to stay connected to the outside world by training earthworms to transmit IP packets, but as you may imagine, this is rather slow. The earthworms have been working nonstop to bring you this issue, which consists of three fun articles I hope you will enjoy: Doug Auclair explains the ins and outs of difference lists, a functional list represen- tation allowing fast concatenation and appending; Neil Brown presents his new InterleaveT abstraction for flexible interleaving of streams of behavior; and Petr Pudl´akexplains abstraction elimination { the process carried out by lambdabot's @pl command { in terms of the Reader monad. By the way, if you happen to meet \me" in real life, beware! It is actually an evil robotic replica. List Leads Off with the Letter λ by Douglas M. Auclair [email protected] The list data type provides a powerful way to operate with a collection of objects using a very simple syntax.
    [Show full text]