173 research outputs found

    Promoting Functions to Type Families in Haskell (extended version)

    Get PDF
    Haskell, as implemented in the Glasgow Haskell Compiler (GHC), is enriched with many extensions that support type-level programming, such as promoted datatypes, kind polymorphism, and type families. Yet, the expressiveness of the type-level language remains limited. It is missing many features present at the term level, including case expressions, anonymous functions, partially-applied functions, and let expressions. In this paper, we present an algorithm – with a proof of correctness – to encode these term-level constructs at the type level. Our approach is automated and capable of promoting a wide array of functions to type families.We also highlight and discuss those term-level features that are not promotable. In so doing, we offer a critique on GHC’s existing type system, showing what it is already capable of and where it may want improvement. We believe that delineating the mismatch between GHC’s term level and its type level is a key step toward supporting dependently typed programming. We have implemented our approach as part of the singletons package, available online

    Promoting Functions to Type Families in Haskell (extended version)

    Get PDF
    Haskell, as implemented in the Glasgow Haskell Compiler (GHC), is enriched with many extensions that support type-level programming, such as promoted datatypes, kind polymorphism, and type families. Yet, the expressiveness of the type-level language remains limited. It is missing many features present at the term level, including case expressions, anonymous functions, partially-applied functions, and let expressions. In this paper, we present an algorithm – with a proof of correctness – to encode these term-level constructs at the type level. Our approach is automated and capable of promoting a wide array of functions to type families.We also highlight and discuss those term-level features that are not promotable. In so doing, we offer a critique on GHC’s existing type system, showing what it is already capable of and where it may want improvement. We believe that delineating the mismatch between GHC’s term level and its type level is a key step toward supporting dependently typed programming. We have implemented our approach as part of the singletons package, available online

    Dependent Types In Haskell: Theory And Practice

    Get PDF
    Haskell, as implemented in the Glasgow Haskell Compiler (GHC), has been adding new type-level programming features for some time. Many of these features---generalized algebraic datatypes (GADTs), type families, kind polymorphism, and promoted datatypes---have brought Haskell to the doorstep of dependent types. Many dependently typed programs can even currently be encoded, but often the constructions are painful. In this dissertation, I describe Dependent Haskell, which supports full dependent types via a backward-compatible extension to today\u27s Haskell. An important contribution of this work is an implementation, in GHC, of a portion of Dependent Haskell, with the rest to follow. The features I have implemented are already released, in GHC 8.0. This dissertation contains several practical examples of Dependent Haskell code, a full description of the differences between Dependent Haskell and today\u27s Haskell, a novel dependently typed lambda-calculus (called Pico) suitable for use as an intermediate language for compiling Dependent Haskell, and a type inference and elaboration algorithm, Bake, that translates Dependent Haskell to type-correct Pico. Full proofs of type safety of Pico and the soundness of Bake are included in the appendix

    Dependently typed array programs don't go wrong

    Get PDF
    AbstractThe array programming paradigm adopts multidimensional arrays as the fundamental data structures of computation. Array operations process entire arrays instead of just single elements. This makes array programs highly expressive and introduces data parallelism in a natural way. Array programming imposes non-trivial structural constraints on ranks, shapes, and element values of arrays. A prominent example where such constraints are violated are out-of-bound array accesses. Usually, such constraints are enforced by means of run time checks. Both the run time overhead inflicted by dynamic constraint checking and the uncertainty of proper program evaluation are undesirable.We propose a novel type system for array programs based on dependent types. Our type system makes dynamic constraint checks obsolete and guarantees orderly evaluation of well-typed programs. We employ integer vectors of statically unknown length to index array types. We also show how constraints on these vectors are resolved using a suitable reduction to integer scalars. Our presentation is based on a functional array calculus that captures the essence of the paradigm without the legacy and obfuscation of a fully-fledged array programming language
    • …
    corecore