Results 1  10
of
59
Programming and Reasoning with Algebraic Effects and Dependent Types
"... One often cited benefit of pure functional programming is that pure code is easier to test and reason about, both formally and informally. However, real programs have sideeffects including state management, exceptions and interactions with the outside world. Haskell solves this problem using monads ..."
Abstract

Cited by 20 (1 self)
 Add to MetaCart
(Show Context)
One often cited benefit of pure functional programming is that pure code is easier to test and reason about, both formally and informally. However, real programs have sideeffects including state management, exceptions and interactions with the outside world. Haskell solves this problem using monads to capture details of possibly sideeffecting computations — it provides monads for capturing State, I/O, exceptions, nondeterminism, libraries for practical purposes such as CGI and parsing, and many others, as well as monad transformers for combining multiple effects. Unfortunately, useful as monads are, they do not compose very well. Monad transformers can quickly become unwieldy when there are lots of effects to manage, leading to a temptation in larger programs to combine everything into one coarsegrained state and exception monad. In this paper I describe an alternative approach based on handling algebraic effects, implemented in the IDRIS programming language. I show how to describe side effecting computations, how to write programs which compose multiple finegrained effects, and how, using dependent types, we can use this approach to reason about states in effectful programs. 1.
Extensible Effects An Alternative to Monad Transformers
"... We design and implement a library that solves the longstanding problem of combining effects without imposing restrictions on their interactions (such as static ordering). Effects arise from interactions between a client and an effect handler (interpreter); interactions may vary throughout the progr ..."
Abstract

Cited by 17 (1 self)
 Add to MetaCart
(Show Context)
We design and implement a library that solves the longstanding problem of combining effects without imposing restrictions on their interactions (such as static ordering). Effects arise from interactions between a client and an effect handler (interpreter); interactions may vary throughout the program and dynamically adapt to execution conditions. Existing code that relies on monad transformers may be used with our library with minor changes, gaining efficiency over long monad stacks. In addition, our library has greater expressiveness, allowing for practical idioms that are inefficient, cumbersome, or outright impossible with monad transformers. Our alternative to a monad transformer stack is a single monad, for the coroutinelike communication of a client with its handler. Its type reflects possible requests, i.e., possible effects of a computation. To support arbitrary effects and their combinations, requests are values of an extensible union type, which allows adding and, notably, subtracting summands. Extending and, upon handling, shrinking of the union of possible requests is reflected in its type, yielding a typeandeffect system for Haskell. The library is lightweight, generalizing the extensible exception handling to other effects and accurately tracking them in types.
Handlers in Action
"... We lay operational foundations for effect handlers. Introduced by Plotkin and Pretnar, effect handlers are a novel programming construct that generalises exception handlers, handling a range of computational effects, such as I/O, state, and nondeterminism. We propose a smallstep structural operatio ..."
Abstract

Cited by 15 (1 self)
 Add to MetaCart
(Show Context)
We lay operational foundations for effect handlers. Introduced by Plotkin and Pretnar, effect handlers are a novel programming construct that generalises exception handlers, handling a range of computational effects, such as I/O, state, and nondeterminism. We propose a smallstep structural operational semantics for a higherorder calculus of effect handlers, along with a sound type and effect system. We explore two alternative effect handler implementation techniques: free monads, and delimited continuations. Finally, we show that Filinski’s monadic reflection can be straightforwardly simulated by effect handlers. 1.
Asymptotic Improvement of Computations over Free Monads
 In Proceedings, Mathematics of Program Construction
, 2008
"... Abstract. We present a loweffort program transformation to improve the efficiency of computations over free monads in Haskell. The development is calculational and carried out in a generic setting, thus applying to a variety of datatypes. An important aspect of our approach is the utilisation of ty ..."
Abstract

Cited by 15 (0 self)
 Add to MetaCart
(Show Context)
Abstract. We present a loweffort program transformation to improve the efficiency of computations over free monads in Haskell. The development is calculational and carried out in a generic setting, thus applying to a variety of datatypes. An important aspect of our approach is the utilisation of type class mechanisms to make the transformation as transparent as possible, requiring no restructuring of code at all. There is also no extra support necessary from the compiler (apart from an uptodate type checker). Despite this simplicity of use, our technique is able to achieve true asymptotic runtime improvements. We demonstrate this by examples for which the complexity is reduced from quadratic to linear. 1
Metatheory à la carte
 In POPL ’13
, 2013
"... Formalizing metatheory, or proofs about programming languages, in a proof assistant has many wellknown benefits. However, the considerable effort involved in mechanizing proofs has prevented it from becoming standard practice. This cost can be amortized by reusing as much of an existing formalizat ..."
Abstract

Cited by 14 (4 self)
 Add to MetaCart
(Show Context)
Formalizing metatheory, or proofs about programming languages, in a proof assistant has many wellknown benefits. However, the considerable effort involved in mechanizing proofs has prevented it from becoming standard practice. This cost can be amortized by reusing as much of an existing formalization as possible when building a new language or extending an existing one. Unfortunately reuse of components is typically adhoc, with the language designer cutting and pasting existing definitions and proofs, and expending considerable effort to patch up the results. This paper presents a more structured approach to the reuse of formalizations of programming language semantics through the composition of modular definitions and proofs. The key contribution is the development of an approach to induction for extensible Church encodings which uses a novel reinterpretation of the universal property of folds. These encodings provide the foundation for a framework, formalized in Coq, which uses type classes to automate the composition of proofs from modular components. Several interesting language features, including binders and general recursion, illustrate the capabilities of our framework. We reuse these features to build fully mechanized definitions and proofs for a number of languages, including a version of miniML. Bounded induction enables proofs of properties for noninductive semantic functions, and mediating type classes enable proof adaptation for more featurerich languages. 1.
Design, Languages
"... Type classes have found a wide variety of uses in Haskell programs, from simple overloading of operators (such as equality or ordering) to complex invariants used to implement typesafe heterogeneous lists or limited subtyping. Unfortunately, many of the richer uses of type classes require extension ..."
Abstract

Cited by 13 (0 self)
 Add to MetaCart
(Show Context)
Type classes have found a wide variety of uses in Haskell programs, from simple overloading of operators (such as equality or ordering) to complex invariants used to implement typesafe heterogeneous lists or limited subtyping. Unfortunately, many of the richer uses of type classes require extensions to the class system that have been incompletely described in the research literature and are not universally accepted within the Haskell community. This paper describes a new type class system, implemented in a prototype tool called ilab, that simplifies and enhances Haskellstyle typeclass programming. In ilab, we replace overlapping instances with a new feature, instance chains, allowing explicit alternation and failure in instance declarations. We describe a technique for ascribing semantics to type class systems, relating classes, instances, and class constraints (such as kind signatures or functional dependencies) directly to a settheoretic model of relations on types. Finally, we give a semantics for ilab and describe its implementation. Categories and Subject Descriptors D.3.2 [Programming Languages]: Language Classifications—Applicative (functional) languages;
Extensibility for the masses: Practical extensibility with object algebras
 IN: ECOOP’12
, 2012
"... This paper presents a new solution to the expression problem (EP) that works in OO languages with simple generics (including Java or C#). A key novelty of this solution is that advanced typing features, including Fbounded quantification, wildcards and variance annotations, are not needed. The solu ..."
Abstract

Cited by 8 (4 self)
 Add to MetaCart
This paper presents a new solution to the expression problem (EP) that works in OO languages with simple generics (including Java or C#). A key novelty of this solution is that advanced typing features, including Fbounded quantification, wildcards and variance annotations, are not needed. The solution is based on object algebras, which are an abstraction closely related to algebraic datatypes and Church encodings. Object algebras also have much in common with the traditional forms of the Visitor pattern, but without many of its drawbacks: they are extensible, remove the need for accept methods, and do not compromise encapsulation. We show applications of object algebras that go beyond toy examples usually presented in solutions for the expression problem. In the paper we develop an increasingly more complex set of features for a miniimperative language, and we discuss a realworld application of object algebras in an implementation of remote batches. We believe that object algebras bring extensibility to the masses: object algebras work in mainstream OO languages, and they significantly reduce the conceptual overhead by using only features that are used by everyday programmers.
The constrainedmonad problem
 In Proceedings of the 18th ACM SIGPLAN international conference on Functional programming. ACM
, 2013
"... In Haskell, there are many data types that would form monads were it not for the presence of typeclass constraints on the operations on that data type. This is a frustrating problem in practice, because there is a considerable amount of support and infrastructure for monads that these data types ca ..."
Abstract

Cited by 8 (1 self)
 Add to MetaCart
(Show Context)
In Haskell, there are many data types that would form monads were it not for the presence of typeclass constraints on the operations on that data type. This is a frustrating problem in practice, because there is a considerable amount of support and infrastructure for monads that these data types cannot use. Using several examples, we show that a monadic computation can be restructured into a normal form such that the standard monad class can be used. The technique is not specific to monads, and we show how it can also be applied to other structures, such as applicative functors. One significant use case for this technique is domainspecific languages, where it is often desirable to compile a deep embedding of a computation to some other language, which requires restricting the types that can appear in that computation.
Modular Tree Automata
"... Abstract. Tree automata are traditionally used to study properties of tree languages and tree transformations. In this paper, we consider tree automata as the basis for modular and extensible recursion schemes. We show, using wellknown techniques, how to derive from standard tree automata highly mo ..."
Abstract

Cited by 7 (6 self)
 Add to MetaCart
(Show Context)
Abstract. Tree automata are traditionally used to study properties of tree languages and tree transformations. In this paper, we consider tree automata as the basis for modular and extensible recursion schemes. We show, using wellknown techniques, how to derive from standard tree automata highly modular recursion schemes. Functions that are defined in terms of these recursion schemes can be combined, reused and transformed in many ways. This flexibility facilitates the specification of complex transformations in a concise manner, which is illustrated with a number of examples. 1
Kleisli arrows of outrageous fortune
, 2011
"... When we program to interact with a turbulent world, we are to some extent at its mercy. To achieve safety, we must ensure that programs act in accordance with what is known about the state of the world, as determined dynamically. Is there any hope to enforce safety policies for dynamic interaction b ..."
Abstract

Cited by 5 (1 self)
 Add to MetaCart
When we program to interact with a turbulent world, we are to some extent at its mercy. To achieve safety, we must ensure that programs act in accordance with what is known about the state of the world, as determined dynamically. Is there any hope to enforce safety policies for dynamic interaction by static typing? This paper answers with a cautious ‘yes’. Monads provide a type discipline for effectful programming, mapping value types to computation types. If we index our types by data approximating the ‘state of the world’, we refine our values to witnesses for some condition of the world. Ordinary monads for indexed types give a discipline for effectful programming contingent on state, modelling the whims of fortune in way that Atkey’s indexed monads for ordinary types do not (Atkey, 2009). Arrows in the corresponding Kleisli category represent computations which a reach a given postcondition from a given precondition: their types are just specifications in a Hoare logic! By way of an elementary introduction to this approach, I present the example of a monad for interacting with a file handle which is either ‘open ’ or ‘closed’, constructed from a command interface specfied Hoarestyle. An attempt to open a file results in a state which is statically unpredictable but dynamically detectable. Well typed programs behave accordingly in either case. Haskell’s dependent type system, as exposed by the Strathclyde Haskell Enhancement preprocessor, provides a suitable basis for this simple experiment. 1