1,777 research outputs found
Programming with Algebraic Effects and Handlers
Eff is a programming language based on the algebraic approach to
computational effects, in which effects are viewed as algebraic operations and
effect handlers as homomorphisms from free algebras. Eff supports first-class
effects and handlers through which we may easily define new computational
effects, seamlessly combine existing ones, and handle them in novel ways. We
give a denotational semantics of eff and discuss a prototype implementation
based on it. Through examples we demonstrate how the standard effects are
treated in eff, and how eff supports programming techniques that use various
forms of delimited continuations, such as backtracking, breadth-first search,
selection functionals, cooperative multi-threading, and others
No value restriction is needed for algebraic effects and handlers
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
A Calculus for Scoped Effects & Handlers
Algebraic effects & handlers have become a standard approach for side-effects
in functional programming. Their modular composition with other effects and
clean separation of syntax and semantics make them attractive to a wide
audience. However, not all effects can be classified as algebraic; some need a
more sophisticated handling. In particular, effects that have or create a
delimited scope need special care, as their continuation consists of two
parts-in and out of the scope-and their modular composition introduces
additional complexity. These effects are called scoped and have gained
attention by their growing applicability and adoption in popular libraries.
While calculi have been designed with algebraic effects & handlers built in to
facilitate their use, a calculus that supports scoped effects & handlers in a
similar manner does not yet exist. This work fills this gap: we present
, a calculus with native support for both algebraic and
scoped effects & handlers. It addresses the need for polymorphic handlers and
explicit clauses for forwarding unknown scoped operations to other handlers.
Our calculus is based on Eff, an existing calculus for algebraic effects,
extended with Koka-style row polymorphism, and consists of a formal grammar,
operational semantics, a (type-safe) type-and-effect system and type inference.
We demonstrate on a range of examples
Inferring Algebraic Effects
We present a complete polymorphic effect inference algorithm for an ML-style
language with handlers of not only exceptions, but of any other algebraic
effect such as input & output, mutable references and many others. Our main aim
is to offer the programmer a useful insight into the effectful behaviour of
programs. Handlers help here by cutting down possible effects and the resulting
lengthy output that often plagues precise effect systems. Additionally, we
present a set of methods that further simplify the displayed types, some even
by deliberately hiding inferred information from the programmer
Answer Refinement Modification: Refinement Type System for Algebraic Effects and Handlers
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
Handling polymorphic algebraic effects
Algebraic effects and handlers are a powerful abstraction mechanism to
represent and implement control effects. In this work, we study their extension
with parametric polymorphism that allows abstracting not only expressions but
also effects and handlers. Although polymorphism makes it possible to reuse and
reason about effect implementations more effectively, it has long been known
that a naive combination of polymorphic effects and let-polymorphism breaks
type safety. Although type safety can often be gained by restricting let-bound
expressions---e.g., by adopting value restriction or weak polymorphism---we
propose a complementary approach that restricts handlers instead of let-bound
expressions. Our key observation is that, informally speaking, a handler is
safe if resumptions from the handler do not interfere with each other. To
formalize our idea, we define a call-by-value lambda calculus that supports
let-polymorphism and polymorphic algebraic effects and handlers, design a type
system that rejects interfering handlers, and prove type safety of our
calculus.Comment: Added the errata for the ESOP'19 paper (page 28
- …