11 research outputs found
Promoting Functions to Type Families in Haskell (extended version)
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)
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
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 letexpressions. 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\u27s existing type system, showing what it is already capable of and where it may want improvement.
We believe that delineating the mismatch between GHC\u27s term level and its type level is a key step toward supporting dependently typed programming
The Thoralf Plugin: For Your Fancy Type Needs
Many fancy types (e.g., generalized algebraic data types, type families) require a type checker plugin. These fancy types have a type index (e.g., type level natural numbers) with an equality relation that is difficult or impossible to represent using GHCâs built-in type equality. The most practical way to represent these equality relations is through a plugin that asserts equality constraints. However, such plugins are difficult to write and reason about. In this paper, we (1) present a formal theory of reasoning about the correctness of type checker plugins for type indices, and, (2) apply this theory in creating Thoralf, a generic and extensible plugin for type indices that translates GHC constraint problems to queries to an external SMT solver. By âgeneric and extensibleâ, we mean the restrictions on extending Thoralf are slight, and, if some type index could be encoded as an SMT sort, then a programmer could extend Thoralf by providing this encoding function
The Thoralf Plugin: For Your Fancy Type Needs
Many fancy types (e.g., generalized algebraic data types, type families) require a type checker plugin. These fancy types have a type index (e.g., type level natural numbers) with an equality relation that is difficult or impossible to represent using GHCâs built-in type equality. The most practical way to represent these equality relations is through a plugin that asserts equality constraints. However, such plugins are difficult to write and reason about. In this paper, we (1) present a formal theory of reasoning about the correctness of type checker plugins for type indices, and, (2) apply this theory in creating Thoralf, a generic and extensible plugin for type indices that translates GHC constraint problems to queries to an external SMT solver. By âgeneric and extensibleâ, we mean the restrictions on extending Thoralf are slight, and, if some type index could be encoded as an SMT sort, then a programmer could extend Thoralf by providing this encoding function
Refinement Reflection:Complete Verification with SMT
We introduce Refinement Reflection, a new framework for building SMT-based
deductive verifiers. The key idea is to reflect the code implementing a
user-defined function into the function's (output) refinement type. As a
consequence, at uses of the function, the function definition is instantiated
in the SMT logic in a precise fashion that permits decidable verification.
Reflection allows the user to write equational proofs of programs just by
writing other programs using pattern-matching and recursion to perform
case-splitting and induction. Thus, via the propositions-as-types principle, we
show that reflection permits the specification of arbitrary functional
correctness properties. Finally, we introduce a proof-search algorithm called
Proof by Logical Evaluation that uses techniques from model checking and
abstract interpretation, to completely automate equational reasoning. We have
implemented reflection in Liquid Haskell and used it to verify that the widely
used instances of the Monoid, Applicative, Functor, and Monad typeclasses
actually satisfy key algebraic laws required to make the clients safe, and have
used reflection to build the first library that actually verifies assumptions
about associativity and ordering that are crucial for safe deterministic
parallelism.Comment: 29 pages plus appendices, to appear in POPL 2018. arXiv admin note:
text overlap with arXiv:1610.0464
Linear/non-Linear Types For Embedded Domain-Specific Languages
Domain-specific languages are often embedded inside of general-purpose host languages so that the embedded language can take advantage of host-language data structures, libraries, and tools. However, when the domain-specific language uses linear types, existing techniques for embedded languages fall short. Linear type systems, which have applications in a wide variety of programming domains including mutable state, I/O, concurrency, and quantum computing, can manipulate embedded non-linear data via the linear type !Ï. However, prior work has not been able to produce linear embedded languages that have full and easy access to host-language data, libraries, and tools.
This dissertation proposes a new perspective on linear, embedded, domain-specific languages derived from the linear/non-linear (LNL) interpretation of linear logic. The LNL model consists of two distinct fragments---one with linear types and another with non-linear types---and provides a simple categorical interface between the two. This dissertation identifies the linear fragment with the linear embedded language and the non-linear fragment with the general-purpose host language.
The effectiveness of this framework is illustrated via a number of examples, implemented in a variety of host languages. In Haskell, linear domain-specific languages using mutable state and concurrency can take advantage of the monad that arises from the LNL model. In Coq, the QWIRE quantum circuit language uses linearity to enforce the no-cloning axiom of quantum mechanics. In homotopy type theory, quantum transformations can be encoded as higher inductive types to simplify the presentation of a quantum equational theory. These examples serve as case studies that prove linear/non-linear type theory is a natural and expressive interface in which to embed linear domain-specific languages
Dependent Types In Haskell: Theory And Practice
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