12 research outputs found
Effects for Efficiency: Asymptotic Speedup with First-Class Control
We study the fundamental efficiency of delimited control. Specifically, we
show that effect handlers enable an asymptotic improvement in runtime
complexity for a certain class of functions. We consider the generic count
problem using a pure PCF-like base language and its extension with
effect handlers . We show that admits an asymptotically
more efficient implementation of generic count than any
implementation. We also show that this efficiency gap remains when
is extended with mutable state. To our knowledge this result is the first of
its kind for control operators
On Model-Checking Higher-Order Effectful Programs (Long Version)
Model-checking is one of the most powerful techniques for verifying systems
and programs, which since the pioneering results by Knapik et al., Ong, and
Kobayashi, is known to be applicable to functional programs with higher-order
types against properties expressed by formulas of monadic second-order logic.
What happens when the program in question, in addition to higher-order
functions, also exhibits algebraic effects such as probabilistic choice or
global store? The results in the literature range from those, mostly positive,
about nondeterministic effects, to those about probabilistic effects, in the
presence of which even mere reachability becomes undecidable. This work takes a
fresh and general look at the problem, first of all showing that there is an
elegant and natural way of viewing higher-order programs producing algebraic
effects as ordinary higher-order recursion schemes. We then move on to consider
effect handlers, showing that in their presence the model checking problem is
bound to be undecidable in the general case, while it stays decidable when
handlers have a simple syntactic form, still sufficient to capture so-called
generic effects. Along the way we hint at how a general specification language
could look like, this way justifying some of the results in the literature, and
deriving new ones
Doo bee doo bee doo
We explore the design and implementation of Frank, a strict functional programming language with a bidirectional effect type system designed from the ground up around a novel variant of Plotkin and Pretnar's effect handler abstraction. Effect handlers provide an abstraction for modular effectful programming: a handler acts as an interpreter for a collection of commands whose interfaces are statically tracked by the type system. However, Frank eliminates the need for an additional effect handling construct by generalising the basic mechanism of functional abstraction itself. A function is but the special case of a Frank operator that interprets no commands. Moreover, Frank's operators can be multihandlers which simultaneously interpret commands from several sources at once, without disturbing the direct style of functional programming with values. Effect typing in Frank employs a novel form of effect polymorphism which avoids mentioning effect variables in source code. This is achieved by propagating an ambient ability inwards, rather than accumulating unions of potential effects outwards. With the ambient ability describing the effects that are available at a certain point in the code, it can become necessary to reconfigure access to the ambient ability. A primary goal is to be able to encapsulate internal effects, eliminating a phenomenon we call effect pollution. Moreover, it is sometimes desirable to rewire the effect flow between effectful library components. We propose adaptors as a means for supporting both effect encapsulation and more general rewiring. Programming with effects and handlers is in its infancy. We contribute an exploration of future possibilities, particularly in combination with other forms of rich type systems
Effect handlers via generalised continuations
Plotkin and Pretnar's effect handlers offer a versatile abstraction for modular programming with user-defined effects. This paper focuses on foundations for implementing effect handlers, for the three different kinds of effect handlers that have been proposed in the literature: deep, shallow, and parameterised. Traditional deep handlers are defined by folds over computation trees, and are the original construct proposed by Plotkin and Pretnar. Shallow handlers are defined by case splits (rather than folds) over computation trees. Parameterised handlers are deep handlers extended with a state value that is threaded through the folds over computation trees. We formulate the extensions both directly and via encodings in terms of deep handlers, and illustrate how the direct implementations avoid the generation of unnecessary closures. We give two distinct foundational implementations of all the kinds of handlers we consider: a continuation passing style (CPS) transformation and a CEK-style abstract machine. In both cases, the key ingredient is a generalisation of the notion of continuation to accommodate stacks of effect handlers. We obtain our CPS translation through a series of refinements as follows. We begin with a first-order CPS translation into untyped lambda calculus which manages a stack of continuations and handlers as a curried sequence of arguments. We then refine the initial CPS translation by uncurrying it to yield a properly tail-recursive translation, and then moving towards more and more intensional representations of continuations in order to support different kinds of effect handlers. Finally, we make the translation higher-order in order to contract administrative redexes at translation time. Our abstract machine design then uses the same generalised continuation representation as the CPS translation. We have implemented both the abstract machine and the CPS transformation (plus extensions) as backends for the Links web programming language
Soundly Handling Linearity
We propose a novel approach to soundly combining linear types with effect
handlers. Linear type systems statically ensure that resources such as file
handles are used exactly once. Effect handlers provide a modular programming
abstraction for implementing features ranging from exceptions to concurrency.
Whereas linear type systems bake in the assumption that continuations are
invoked exactly once, effect handlers allow continuations to be discarded or
invoked more than once. This mismatch leads to soundness bugs in existing
systems such as the programming language Links, which combines linearity (for
session types) with effect handlers. We introduce control flow linearity as a
means to ensure that continuations are used in accordance with the linearity of
any resources they capture, ruling out such soundness bugs.
We formalise control flow linearity in a System F-style core calculus Feffpop
equipped with linear types, effect types, and effect handlers. We define a
linearity-aware semantics to formally prove that Feffpop preserves the
integrity of linear values in the sense that no linear value is discarded or
duplicated. In order to show that control flow linearity can be made practical,
we adapt Links based on the design of Feffpop, in doing so fixing a
long-standing soundness bug.
Finally, to better expose the potential of control flow linearity, we define
an ML-style core calculus Qeffpop, based on qualified types, which requires no
programmer provided annotations, and instead relies entirely on type inference
to infer control flow linearity. Both linearity and effects are captured by
qualified types. Qeffpop overcomes a number of practical limitations of
Feffpop, supporting abstraction over linearity, linearity dependencies between
type variables, and a much more fine-grained notion of control flow linearity.Comment: 51 pages, accepted for POPL 202
Introducing ⦇ λ ⦈, a λ-calculus for effectful computation
International audienceWe present λ , a calculus with special constructions for dealing with effects and handlers. This is an extension of the simply-typed λ-calculus (STLC). We enrich STLC with a type for representing effectful computations alongside with operations to create and process values of this type. The calculus is motivated by natural language modelling, and especially semantic representation. Traditionally, the meaning of a sentence is calculated using λ-terms, but some semantic phenomena need more flexibility. In this article we introduce the calculus and show that the calculus respects the laws of algebraic structures and it enjoys strong normalisation. To do so, confluence is proven using the Combinatory Reduction Systems (CRSs) of Klop and termination using the Inductive Data Type Systems (IDTSs) of Blanqui
A Separation Logic for Effect Handlers
International audienceUser-defined effects and effect handlers are advertised and advocated as a relatively easy-to-understand and modular approach to delimited control. They offer the ability of suspending and resuming a computation and allow information to be transmitted both ways between the computation, which requests a certain service, and the handler, which provides this service. Yet, a key question remains, to this day, largely unanswered: how does one modularly specify and verify programs in the presence of both user-defined effect handlers and primitive effects, such as heap-allocated mutable state? We answer this question by presenting a Separation Logic with built-in support for effect handlers, both shallow and deep. The specification of a program fragment includes a protocol that describes the effects that the program may perform as well as the replies that it can expect to receive. The logic allows local reasoning via a frame rule and a bind rule. It is based on Iris and inherits all of its advanced features, including support for higher-order functions, user-defined ghost state, and invariants. We illustrate its power via several case studies, including (1) a generic formulation of control inversion, which turns a producer that "pushes" elements towards a consumer into a producer from which one can "pull" elements on demand, and (2) a simple system for cooperative concurrency, where several threads execute concurrently, can spawn new threads, and communicate via promises