The development of programming languages can be quite complicated and costly. Hence, much effort has been devoted to the modular definition of language features that can be reused in various combinations to define new languages and experiment with their semantics. A notable outcome of these efforts is the algebra-based "datatypes a la carte" (DTC) approach. When combined with algebraic effects, DTC can model a wide range of common language features. Unfortunately, the current state of the art does not cover modular definitions of advanced control-flow mechanisms that defer execution to an appropriate point, such as call-by-name and call-by-need evaluation, as well as (multi-)staging. This paper defines latent effects, a generic class of such control-flow mechanisms. We demonstrate how function abstractions, lazy computations and a MetaML-like staging can all be expressed in a modular fashion using latent effects, and how they can be combined in various ways to obtain complex semantics. We provide a full Haskell implementation of our effects and handlers with a range of examples.
翻译:编程语言的发展可能相当复杂,费用也很高。因此,已作出大量努力,对语言特征进行模块化定义,这些特征可以重新用于各种组合,以界定新语言并试验语义学。这些努力的一个显著成果是代数“数据型”法(DTC),当与代数效应相结合时,DTC可以建模多种共同语言特征。不幸的是,目前的最新技术并不包括先进控制流程机制的模块化定义,将执行推迟到适当点,例如按名和按需调用的评价以及(多功能)处理。本文界定了潜在效应,即这种控制流程机制的通用类别。我们展示了如何利用潜在效应以模块化方式表达抽象、懒惰计算和类似MetML的演变,以及如何以各种方式将其组合起来,以获得复杂的语义学。我们用一系列实例充分介绍我们的效果和处理者。