一句话:提出选择性应用函子,介于应用函子与单子之间,可静态声明效果并动态选择执行。
应用函子与单子广泛用于函数式编程中描述带效果的计算:前者组合相互独立、静态声明的效果,后者允许后续效果依赖先前计算值而动态组合。本文引入选择性应用函子(selective applicative functors)这一中间抽象:所有效果仍需静态声明,但可以在运行时动态选择执行其中哪些效果。文章给出该抽象的理论接口与若干示例,并展示两个工业案例研究,说明其能表达比应用函子更灵活、又比单子更受限且可分析的效果组合。
Applicative functors and monads have conquered the world of functional programming by providing general and powerful ways of describing effectful computations using pure functions. Applicative functors provide a way to compose independent effects that cannot depend on values produced by earlier computations, and all of which are declared statically. Monads extend the applicative interface by making it possible to compose dependent effects, where the value computed by one effect determines all subsequent effects, dynamically. This paper introduces an intermediate abstraction called selective applicative functors that requires all effects to be declared statically, but provides a way to select which of the effects to execute dynamically. We demonstrate applications of the new abstraction on several examples, including two industrial case studies.
@article{paperbot598,
title = {Selective applicative functors},
author = {Andrey Mokhov and Georgy Lukyanov and Simon Marlow and Jeremie Dimino},
journal = {Proceedings of the ACM on Programming Languages},
volume = {3},
number = {ICFP},
year = {2019},
doi = {10.1145/3341694}
}