一句话:提出关联效应,使类型类能抽象其函数签名中的效应、由各实例指定具体效应,并在 Flix 中实现。
论文针对类型与效应系统同类型类结合时表达力受限的问题:类型类无法对其方法签名中的效应进行抽象,因而难以同时刻画纯函数与可能抛异常的偏函数、不可变数据结构与带堆效应的可变数据结构。作者提出「关联效应」(associated effects),允许类型类对其函数签名的效应进行抽象,并由每个类型类实例给出具体效应,从而在保留类型类抽象能力的同时支持效应多态。该特性实现为 Flix 语言的扩展,并据此重构 Flix 标准库:为 11 个类型类加入关联效应,新增 28 个类型类实例。三个典型应用包括抽象全函数与偏函数、抽象不可变与带堆效应的可变数据结构,以及实现将类型类与代数效应结合的适配器,显著提升了语言的灵活性与表达力。
We present associated effects, a programming language feature that enables type classes to abstract over the effects of their function signatures, allowing each type class instance to specify its concrete effects. Associated effects significantly increase the flexibility and expressive power of a programming language that combines a type and effect system with type classes. In particular, associated effects allow us to (i) abstract over total and partial functions, where partial functions may throw exceptions, (ii) abstract over immutable data structures and mutable data structures that have heap effects, and (iii) implement adaptors that combine type classes with algebraic effects. We implement associated effects as an extension of the Flix programming language and refactor the Flix Standard Library to use associated effects, significantly increasing its flexibility and expressive power. Specifically, we add associated effects to 11 type classes, which enables us to add 28 new type class instances. CCS Concepts: • Software and its engineering → Language features .
@article{paperbot2517,
title = {Associated Effects: Flexible Abstractions for Effectful Programming},
author = {Matthew Lutze and Magnus Madsen},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {PLDI},
year = {2024},
doi = {10.1145/3656393}
}