11 research outputs found

    A Simple Semantics for ML Polymorphism

    Get PDF
    We give a framework for denotational semantics for the polymorphic core of the programming language ML. This framework requires no more semantic material than what is needed for modeling the simple type discipline. In our view, the terms of ML are pairs consisting of a raw (untyped) lambda term and a type-scheme that ML\u27s type inference system can derive for the raw term. We interpret type-schemes as sets of simple types. Then, given any model M of the simply typed lambda calculus, the meaning of an ML term will be a set of pairs, each consisting of a simple type Ï„ and an element of M of type Ï„. Hence, there is no need to interpret all raw terms, as was done in Milner\u27s original semantic framework. In comparison to Mitchell and Harper\u27s analysis, we avoid having to provide a very large type universe in which generic type-schemes are interpreted. Also, we show how to give meaning to ML terms rather than to derivations in the ML type inference system (which can be several for the same term). We give an axiomatization for the equational theory that corresponds to our semantic framework and prove the analogs of the compeleteness theorems that Friedman proved for the simply typed lambda calculus. The framework can be extended to languages with constants, type constructors and recursive types (via regular trees). For the extended language, we prove a theorem that allows the transfer of certain full abstraction results from languages based on the typed lambda calculus to ML-like languages

    ML typing, explicit polymorphism and qualified types

    Full text link

    Revisiting Ad-hoc Polymorphism

    Get PDF
    Ad-hoc polymorphism is a type of polymorphism where different function definitions can be given the same name. Programming languages utilize constructs like Type classes and Object classes to provide a mechanism for implementing ad-hoc polymorphism. System O, by Odersky, Wadler, and Wehr is a language which defines a dynamic semantics that supports ad-hoc polymorphism. It also describes static type checking for its programs and a transformation to the Hindley/Milner system. In this study, we present extensions to System O by defining constructs that make the language more practical to use. We utilize the dynamic semantics to define the ability to express type classes. We define additional optimizations on the transform that aim to reduce redundant function calls at run-time and simplify the generated code. Finally, we implement an interpreter for this programming language in Clojure, and provide several examples of programs utilizing ad-hoc polymorphism with the constructs we have defined

    Polymorphism and Inference in Database Programming

    Get PDF
    The polymorphic type system of ML can be extended in two ways to make it the appropriate basis of a database programming language. The first is an extension to the language of types that captures the polymorphic nature of field selection; the second is a technique that generalizes relational operators to arbitrary data structures. The combination provides a statically typed language in which relational databases may be cleanly represented as typed structures. As in ML types are inferred, which relieves the programmer of making the rather complicated type assertions that may be required to express the most general type of a program that involving field selection and generalized relational operators. These extensions may also be used to provide static polymorphic typechecking in object-oriented languages and databases. A problem that arises with object-oriented databases is the apparent need for dynamic typechecking when dealing with queries on heterogeneous collections of objects. An extension of the type system needed for generalized relational operations can also be used for manipulating collections of dynamically typed values in a statically typed language. A prototype language based on these ideas has been implemented. While it lacks a proper treatment of persistent data, it demonstrates that a wide variety of database structures can be cleanly represented in a polymorphic programming language

    A simple semantics for Haskell overloading

    Get PDF
    As originally proposed, type classes provide overloading and ad-hoc definition, but can still be understood (and implemented) in terms of strictly parametric calculi. This is not true of subsequent extensions of type classes. Functional dependencies and equality constraints allow the satisfiability of predicates to refine typing; this means that the interpretations of equivalent qualified types may not be interconvertible. Overlapping instances and instance chains allow predicates to be satisfied without determining the implementations of their associated class methods, introducing truly non-parametric behavior. We propose a new approach to the semantics of type classes, interpreting polymorphic expressions by the behavior of each of their ground instances, but without requiring that those behaviors be parametrically determined. We argue that this approach both matches the intuitive meanings of qualified types and accurately models the behavior of programsComment: Originally presented at Haskell 201

    Polymorphism and Type Inference in Database Programming

    Get PDF

    Abstract Interpretation of Polymorphic Higher-Order Functions

    Get PDF
    This thesis describes several abstract interpretations of polymorphic functions. In all the interpretations, information about any instance of a polymorphic function is obtained from that of the smallest, thus avoiding the computation of the instance directly. This is useful in the case of recursive functions, because it avoids the expensive computation of finding fixed points of functionals corresponding to complex instances. We define an explicitly typed polymorphic language with the Hindley-Milner type system to illustrate our ideas, and provide two semantics of polymorphism that relate separate instances of any polymorphic function. The choice of which semantics to use depends on the particular program analysis we want to study. For studying strictness analysis and binding-time analysis, we introduce a semantics based on embedding-closure pairs. We see how the abstract function of the smallest instance of a polymorphic function is used in building an approximation to that of any instance. Furthermore, we extend the language to include lists, and describe both strictness analysis and binding-time analysis of lists. Thus, this work extends previous work by others, on analyses of polymorphic first-order functions and also of monomorphic higher-order functions, to polymorphic higher-order functions. In relating distinct instances of a polymorphic function, the approximate abstract function is expressed as the greatest lower bound of a set of functions. This may not be very cheap to compute. However, there are often ways of obtaining the same result by considering a smaller set of functions. Another issue concerns how close the approximations are to the exact values. In the first-order case, it is shown that the approximate values coincide with the exact values. In general this is not the case, but experimental results on strictness analysis indicate that good approximations are obtained. Embedding-projection pairs are used to provide a semantics that is convenient for termination analysis of polymorphic functions. We show that the abstract interpretation of an instance can be approximated by the least upper bound of a set of functions that are built from that of the smallest

    Type Classes and Instance Chains: A Relational Approach

    Get PDF
    Type classes, first proposed during the design of the Haskell programming language, extend standard type systems to support overloaded functions. Since their introduction, type classes have been used to address a range of problems, from typing ordering and arithmetic operators to describing heterogeneous lists and limited subtyping. However, while type class programming is useful for a variety of practical problems, its wider use is limited by the inexpressiveness and hidden complexity of current mechanisms. We propose two improvements to existing class systems. First, we introduce several novel language features, instance chains and explicit failure, that increase the expressiveness of type classes while providing more direct expression of current idioms. To validate these features, we have built an implementation of these features, demonstrating their use in a practical setting and their integration with type reconstruction for a Hindley-Milner type system. Second, we define a set-based semantics for type classes that provides a sound basis for reasoning about type class systems, their implementations, and the meanings of programs that use them

    Defined algebraic operations

    Get PDF
    Defined algebraic operations ("DAO") is a novel model of programming, which sits broadly between imperative and purely functional programming. DAO expresses many control-flow idioms in a fashion similar to algebraic effect handling. But operation definition is lexical, and commutes with sequencing (when that type-checks). DAO has three particular strengths. Firstly, DAO automatically avoids name clashes when writing higher-order programs with nonlocal control. This is demonstrated with a simple example. Secondly, certain buggy programs do not type check due to the lexical nature of DAO. Thirdly, it validates a strong "theory-dependent" logic, which uses properties of operation definitions to add equivalences inside their scope. For instance, under an operation definition for state, most state equations hold, even under lambdas --- the analogous statement for handling is false. This lends extra credibility to the claim that DAO is a form of user-defined effects. To substantiate these claims, we give a concrete DAO language and logic based on the fine-grain call-by-value lambda calculus, and a number of examples. As an additional contribution, we give a simpler presentation of a method for proving coherence of denotational semantics, first presented in a more sophisticated setting by Biernacki and Polesiuk
    corecore