arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1905.06544cs.PLcs.LOcs.SC
收藏

没有单子的效应:非决定论--回到Meta语言

Effects Without Monads: Non-determinism -- Back to the Meta Language

Oleg Kiselyov

摘要:

我们反思了具有复杂效果的编程,回顾了一个不值得遗忘的一元编程的替代方案,并检查了它在现代函数式语言中的实际工作情况。我们采用并论证了一个有效的程序分解成一个一阶有效的DSL与丰富的,高阶的“宏”系统的位置。不是所有的程序都可以这样分解。虽然这种方法不是通用的,但它确实允许有趣的程序。有效的DSL同样是针对特定问题的,缺乏通用的一元组合,甚至函数。从好的方面来说,它优雅地表达了问题,易于实现和推理,并且适合于非标准的解释,如代码生成(编译)和抽象解释。一个专门化的DSL易于频繁扩展;无标签的最终风格的DSL嵌入的经验表明,DSL的发展可以是无痛的,具有最大的代码重用。我们说明了一个简单但有代表性的例子,一个相当复杂的效果-非决定论,包括承诺的选择的论点。出乎意料的是,事实证明,我们可以用类似ML的语言编写有趣的非确定性程序,就像在函数逻辑语言Curry中一样自然和优雅-不仅运行它们,而且静态分析,优化和编译。实际上,Meta语言的丰富性弥补了有效DSL的简单性。关键思想可以追溯到ML作为Edinburgh LCF定理证明器的Meta语言的起源。而不是使用ML来构建定理,我们现在构建(DSL)程序。

英文摘要:

We reflect on programming with complicated effects, recalling an undeservingly forgotten alternative to monadic programming and checking to see how well it can actually work in modern functional languages. We adopt and argue the position of factoring an effectful program into a first-order effectful DSL with a rich, higher-order 'macro' system. Not all programs can be thus factored. Although the approach is not general-purpose, it does admit interesting programs. The effectful DSL is likewise rather problem-specific and lacks general-purpose monadic composition, or even functions. On the upside, it expresses the problem elegantly, is simple to implement and reason about, and lends itself to non-standard interpretations such as code generation (compilation) and abstract interpretation. A specialized DSL is liable to be frequently extended; the experience with the tagless-final style of DSL embedding shown that the DSL evolution can be made painless, with the maximum code reuse. We illustrate the argument on a simple but representative example of a rather complicated effect -- non-determinism, including committed choice. Unexpectedly, it turns out we can write interesting non-deterministic programs in an ML-like language just as naturally and elegantly as in the functional-logic language Curry -- and not only run them but also statically analyze, optimize and compile. The richness of the Meta Language does, in reality, compensate for the simplicity of the effectful DSL. The key idea goes back to the origins of ML as the Meta Language for the Edinburgh LCF theorem prover. Instead of using ML to build theorems, we now build (DSL) programs.

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

↑