Affiliation:
1. Waseda University, Tokyo, Japan
2. University of Tsukuba, Tsukuba, Japan
3. National Institute of Informatics, Tokyo, Japan
Abstract
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
. While a variety of refinement type systems have been proposed, 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 languages with 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 such 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, or ATM) and prove its soundness. Additionally, as a proof of concept, we have extended the refinement type system to a subset of OCaml 5 which comes with a built-in support for effect handlers, implemented a type checking and inference algorithm for the extension, and evaluated it on a number of benchmark programs that use algebraic effects and handlers. 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 without delimited continuations. We investigate this alternative in the paper, 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. We show that there are pros and cons with this approach, namely, while one can use an existing refinement type checking and inference algorithm that can only (directly) handle pure programs, there are issues such as needing type annotations in source programs and making the inferred types less informative to a user.
Funder
Japan Society for the Promotion of Science
Core Research for Evolutional Science and Technology
Publisher
Association for Computing Machinery (ACM)
Reference58 articles.
1. Handling fibred algebraic effects
2. Danel Ahman and Gordon Plotkin. 2015. Refinement types for algebraic effects. In Abstracts of the 21st Meeting ‘Types for Proofs and Programs’ (TYPES). Institute of Cybernetics, Tallinn University of Technology, 10–11.
3. Compiling with Continuations
4. On typing delimited continuations: three new solutions to the printf problem
5. Andrej Bauer. 2018. What is algebraic about algebraic effects and handlers? CoRR, abs/1807.05923 (2018), arXiv:1807.05923. arxiv:1807.05923
Cited by
2 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献