arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1202.2921cs.PL
收藏

一元计算的求值策略

Evaluation strategies for monadic computations

Tomas Petricek

摘要:

单子已成为函数式编程中构建有效计算的强大工具,因为它们使效果的顺序显式化。当将纯代码转换为一元版本时,我们需要显式地指定求值顺序。两种标准的翻译给出了按值调用和按名称调用的语义。由此产生的程序具有不同的结构和类型,这使得重新选择变得困难。在本文中,我们使用一个额外的操作malias将纯代码转换为一元代码,该操作抽象出了评估策略。malias操作基于计算comonads;我们使用分类框架来指定操作所需的定律。对于任何monad,我们展示了malias的实现,它提供了按值调用和按名称调用的语义。虽然我们没有给所有的单子需要调用的语义,我们展示了如何把某些单子到一个扩展的单子与需要调用的语义,这部分回答了一个悬而未决的问题。此外,使用我们的统一翻译,它是可能的,以改变功能代码翻译为一元形式的评估策略,而不改变其结构或类型。

英文摘要:

Monads have become a powerful tool for structuring effectful computations in functional programming, because they make the order of effects explicit. When translating pure code to a monadic version, we need to specify evaluation order explicitly. Two standard translations give call-by-value and call-by-name semantics. The resulting programs have different structure and types, which makes revisiting the choice difficult. In this paper, we translate pure code to monadic using an additional operation malias that abstracts out the evaluation strategy. The malias operation is based on computational comonads; we use a categorical framework to specify the laws that are required to hold about the operation. For any monad, we show implementations of malias that give call-by-value and call-by-name semantics. Although we do not give call-by-need semantics for all monads, we show how to turn certain monads into an extended monad with call-by-need semantics, which partly answers an open question. Moreover, using our unified translation, it is possible to change the evaluation strategy of functional code translated to the monadic form without changing its structure or types.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑