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

让(rec)插入没有效果,灯光或魔术

let (rec) insertion without Effects, Lights or Magic

Oleg Kiselyov, Jeremy Yallop

摘要:

程序生成中的Let插入是用定义(let语句)生成代码。虽然在生成的代码中定义在使用之前,但在代码生成期间,“使用”是第一位的:我们甚至可能不知道需要定义,直到我们遇到一个重复出现的表达式。因此,定义是“事后”产生的,这就解释了为什么这一过程难以理解和执行-对于参数化、递归和相互递归的定义更是如此。我们在前面已经介绍了一个let(rec)插入的接口--即用于生成(相互递归的)定义。我们展示了它的表现力和应用程序,但没有展示它的实现,因为它依赖于效果和编译器的魔力。我们现在展示如何理解let插入,并因此在普通OCaml中实现它。我们给出了let(rec)-插入的第一个指称语义,它完全不依赖于任何效果。该形式化指导了当前MetaOCaml版本中let(rec)插入的实现。

英文摘要:

Let insertion in program generation is producing code with definitions (let-statements). Although definitions precede uses in generated code, during code generation `uses' come first: we might not even know a definition is needed until we encounter a reoccurring expression. Definitions are thus generated `in hindsight', which explains why this process is difficult to understand and implement -- even more so for parameterized, recursive and mutually recursive definitions. We have earlier presented an interface for let(rec) insertion -- i.e. for generating (mutually recursive) definitions. We demonstrated its expressiveness and applications, but not its implementation, which relied on effects and compiler magic. We now show how one can understand let insertion, and hence implement it in plain OCaml. We give the first denotational semantics of let(rec)-insertion, which does not rely on any effects at all. The formalization has guided the implementation of let(rec) insertion in the current version of MetaOCaml.

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

↑