【24h】

Building interpreters by composing monads

机译:通过编写单子来构建口译员

获取原文

摘要

We exhibit a set of functions coded in Haskell that can be used as building blocks to construct a variety of interpreters for Lisp-like languages. The building blocks are joined merely through functional composition. Each building block contributes code to support a specific feature, such as numbers, continuations, functions calls, or nondeterminism. The result of composing some number of building blocks is a parser, an interpreter, and a printer that support exactly the expression forms and data types needed for the combined set of features, and no more.

The data structures are organized as pseudomonads, a generalization of monads that allows composition. Functional composition of the building blocks implies type composition of the relevant pseudomonads.

Our intent was that the Haskell type resolution system ought to be able to deduce the appropriate data types automatically. Unfortunately there is a deficiency in current Haskell implementations related to recursive data types: circularity must be reflected statically in the type definitions.

We circumvent this restriction by applying a purpose-built program simplifier that performs partial evaluation and a certain amount of program algebra. We construct a wide variety of interpreters in the style of Wadler by starting with the building blocks and a page of boiler-plate code, writing three lines of code (one to specify the building blocks and two to (redundantly) specify type compositions), and then applying the simplifier. The resulting code is acceptable Haskell code.

We have tested a dozen different interpreters with various combinations of features. In this paper we discuss the overall code structuring strategy, exhibit several building blocks, briefly describe the partial evaluator, and present a number of automatically generated interpreters.

机译:

我们展示了一组用Haskell编码的函数,可以用作构建类似Lisp语言的各种解释器的构造块。这些构建块仅通过功能组成进行连接。每个构件块贡献代码以支持特定功能,例如数字,连续性,函数调用或不确定性。组成一定数量的构建块的结果是解析器,解释器和打印机,它们完全支持组合功能集所需的表达式形式和数据类型,而不再支持。

数据结构被组织为 pseudomonads ,这是允许组合的monad的概括。构建基块的功能组成暗示了相关假单胞菌的类型组成。

我们的目的是Haskell类型解析系统应该能够自动推断出适当的数据类型。不幸的是,当前与递归数据类型相关的Haskell实现存在缺陷:圆形性必须在类型定义中静态反映。

我们通过应用专用的程序简化程序来规避此限制,该程序可以执行部分​​评估和一定数量的程序代数。我们以Wadler风格构造各种各样的解释器,首先从构建块和样板代码页面开始,编写三行代码(其中一行用于指定构件,两行用于(冗余)指定类型组成),然后应用简化器。结果代码是可接受的Haskell代码。

我们已经测试了十几种具有各种功能组合的不同口译员。在本文中,我们讨论了整体代码结构化策略,展示了几个构建块,简要描述了部分评估器,并介绍了许多自动生成的解释器。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号