8 research outputs found

    No value restriction is needed for algebraic effects and handlers

    Full text link
    We present a straightforward, sound Hindley-Milner polymorphic type system for algebraic effects and handlers in a call-by-value calculus, which allows type variable generalisation of arbitrary computations, not just values. This result is surprising. On the one hand, the soundness of unrestricted call-by-value Hindley-Milner polymorphism is known to fail in the presence of computational effects such as reference cells and continuations. On the other hand, many programming examples can be recast to use effect handlers instead of these effects. Analysing the expressive power of effect handlers with respect to state effects, we claim handlers cannot express reference cells, and show they can simulate dynamically scoped state

    On the Expressive Power of User-Defined Effects: Effect Handlers, Monadic Reflection, Delimited Control

    Get PDF
    We compare the expressive power of three programming abstractions for user-defined computational effects: Bauer and Pretnar's effect handlers, Filinski's monadic reflection, and delimited control without answer-type-modification. This comparison allows a precise discussion about the relative expressiveness of each programming abstraction. It also demonstrates the sensitivity of the relative expressiveness of user-defined effects to seemingly orthogonal language features. We present three calculi, one per abstraction, extending Levy's call-by-push-value. For each calculus, we present syntax, operational semantics, a natural type-and-effect system, and, for effect handlers and monadic reflection, a set-theoretic denotational semantics. We establish their basic meta-theoretic properties: safety, termination, and, where applicable, soundness and adequacy. Using Felleisen's notion of a macro translation, we show that these abstractions can macro-express each other, and show which translations preserve typeability. We use the adequate finitary set-theoretic denotational semantics for the monadic calculus to show that effect handlers cannot be macro-expressed while preserving typeability either by monadic reflection or by delimited control. We supplement our development with a mechanised Abella formalisation

    Answer Refinement Modification: Refinement Type System for Algebraic Effects and Handlers

    Full text link
    Algebraic effects and handlers are a mechanism to structure programs with computational effects in a modular way. They are recently gaining popularity and being adopted in practical languages, such as OCaml. Meanwhile, there has been substantial progress in program verification via refinement type systems. However, thus far, there has not been a satisfactory refinement type system for algebraic effects and handlers. In this paper, we fill the void by proposing a novel refinement type system for algebraic effects and handlers. The expressivity and usefulness of algebraic effects and handlers come from their ability to manipulate delimited continuations, but delimited continuations also complicate programs' control flow and make their verification harder. To address the complexity, we introduce a novel concept that we call answer refinement modification (ARM for short), which allows the refinement type system to precisely track what effects occur and in what order when a program is executed, and reflect the information as modifications to the refinements in the types of delimited continuations. We formalize our type system that supports ARM (as well as answer type modification) and prove its soundness. Additionally, as a proof of concept, we have implemented a corresponding type checking and inference algorithm for a subset of OCaml 5, and evaluated it on a number of benchmark programs. The evaluation demonstrates that ARM is conceptually simple and practically useful. Finally, a natural alternative to directly reasoning about a program with delimited continuations is to apply a continuation passing style (CPS) transformation that transforms the program to a pure program. We investigate this alternative, and show that the approach is indeed possible by proposing a novel CPS transformation for algebraic effects and handlers that enjoys bidirectional (refinement-)type-preservation.Comment: 66 page

    Accompanying material for the article 'no value restriction is needed for algebraic effects and handlers'

    No full text
    We present a straightforward, sound, Hindley-Milner polymorphic type system for algebraic effects and handlers in a call-by-value calculus, which, to our surprise, allows type variable generalisation of arbitrary computations, and not just values. The soundness of unrestricted call-by-value Hindley-Milner polymorphism is known to fail in the presence of computational effects such as reference cells and continuations, and many programming examples can be recast to use effect handlers instead of these effects. This file formalises in Twelf the calculus and its soundness proof. Accompannying material for _No value restriction is needed for algebraic effects and handlers_ ============================================================================================== [Ohad Kammar](http://www.cs.ox.ac.uk/people/ohad.kammar) and [Matija Pretnar](http://matija.pretnar.info/) This code (value-restriction.tar.gz) formalises the basic meta-theoretic properties of the different variations of the calculus presented in the aforementioned article. The code is based on [Matija Pretnar and Andrej Bauer's formalisation](https://github.com/matijapretnar/twelf-eff/) of the core of the [Eff](http://www.eff-lang.org/) programming language. For an explanation of the basic concepts of core Eff, please refer to the aforementioned article, and to the article [An Effect System for Algebraic Effects and Handlers (http://arxiv.org/abs/1306.6316) as the comments in the code serve only to highlight implementation details. ## Running the code The formalization is written in [Twelf](http://www.twelf.org/). To install it, please see the [official instructions](http://www.twelf.org/wiki/Download). The simplest way to run the code is to open any `.elf` file in Emacs, and load the configuration by entering `Ctrl-C Ctrl-C` and confirming the default locations (unless you moved them to a different location). Alternatively, you can run `twelf-server` in the main directory, and type `make`. ## The formalisations * `local-sig`: the calculus in the article, with fully annotated local signatures * `shallow`: a variation on the local-sig calculus, where handlers are shallow * `global-sig`: a coarsely-annotated variation of the calculus, with a single, global, effect signature * `jumbo`: the coarsely-annotated calculus extended with fixed-points, structural subtyping, and static effect instances ## The structure of each formalisation Each sub-directory has approximately the same structure: * `sources.cfg`: Twelf configuration file determining the order of files ### Core language * `effects.elf`: definitions involving operations, regions and dirt * `effects-lemmas.elf`: various lemmas about the above definitions * `syntax.elf`: abstract syntax Since types and dirts are mutually defined in `local-sig`, the files `effects.elf` and `syntax.elf` are merged, and `effects-lemmas.elf` is named `syntax-lemmas.elf`. ### Static semantics * `typing.elf`: definition of typing judgments * `typing-lemmas.elf`: various typing lemmas, mainly substitution lemma The formalisation `jumbo` also contains files `subtyping.elf` and `subtyping-lemmas.elf` that contain appropriate definitions and lemmas for subtyping. ### Dynamic semantics * `operational.elf`: definition of small step and big step operational semantics ### Safety theorems * `progress-lemmas.elf`: lemmas used in `progress.elf` * `progress.elf`: the progress theorem * `preservation-lemmas.elf`: lemmas used in `preservation.elf` * `preservation.elf`: the preservation theore

    Accompanying material for the article 'no value restriction is needed for algebraic effects and handlers'

    No full text
    We present a straightforward, sound, Hindley-Milner polymorphic type system for algebraic effects and handlers in a call-by-value calculus, which, to our surprise, allows type variable generalisation of arbitrary computations, and not just values. The soundness of unrestricted call-by-value Hindley-Milner polymorphism is known to fail in the presence of computational effects such as reference cells and continuations, and many programming examples can be recast to use effect handlers instead of these effects. This file formalises in Twelf the calculus and its soundness proof
    corecore