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

書誌事項

公開日
2024-01-02
資源種別
journal article
権利情報
  • https://creativecommons.org/licenses/by/4.0/
DOI
  • 10.1145/3633280
  • 10.48550/arxiv.2307.15463
公開者
Association for Computing Machinery (ACM)

説明

<jats:p> 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 <jats:italic toggle="yes">refinement type systems</jats:italic> . 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 <jats:italic toggle="yes">delimited continuations</jats:italic> , 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 <jats:italic toggle="yes">answer refinement modification</jats:italic> (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 <jats:italic toggle="yes">type</jats:italic> 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. </jats:p> <jats:p> Finally, a natural alternative to directly reasoning about a program with delimited continuations is to apply a <jats:italic toggle="yes">continuation passing style</jats:italic> (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. </jats:p>

収録刊行物

被引用文献 (2)*注記

もっと見る

参考文献 (54)*注記

もっと見る

関連プロジェクト

もっと見る

詳細情報 詳細情報について

問題の指摘

ページトップへ