【24h】

Lightweight Monadic Programming in ML

机译:ML中的轻量级Monadic编程

获取原文
获取原文并翻译 | 示例

摘要

Many useful programming constructions can be expressed as monads. Examples include probabilistic modeling, functional reactive programming, parsing, and information flow tracking, not to mention effectful functionality like state and I/O. In this paper, we present a type-based rewriting algorithm to make programming with arbitrary monads as easy as using ML's built-in support for state and I/O. Developers write programs using monadic values of type m τ as if they were of type τ, and our algorithm inserts the necessary binds, units, and monad-to-monad morphisms so that the program type checks. Our algorithm, based on Jones' qualified types, produces principal types. But principal types are sometimes problematic: the program's semantics could depend on the choice of instantiation when more than one instantiation is valid. In such situations we are able to simplify the types to remove any ambiguity but without adversely affecting typability; thus we can accept strictly more programs. Moreover, we have proved that this simplification is efficient (linear in the number of constraints) and coherent: while our algorithm induces a particular rewriting, all related rewritings will have the same semantics. We have implemented our approach for a core functional language and applied it successfully to simple examples from the domains listed above, which are used as illustrations throughout the paper.
机译:许多有用的编程构造都可以表示为monad。示例包括概率建模,功能性反应式编程,解析和信息流跟踪,更不用说诸如状态和I / O之类的有效功能了。在本文中,我们提出了一种基于类型的重写算法,使使用任意monad进行编程就像使用ML对状态和I / O的内置支持一样容易。开发人员使用mτ类型的单子值来编写程序,就好像它们是τ类型一样,并且我们的算法会插入必要的绑定,单位和单子到单子态,以便检查程序类型。我们基于琼斯合格类型的算法产生主体类型。但是主体类型有时会出现问题:当一个以上的实例有效时,程序的语义可能取决于实例的选择。在这种情况下,我们可以简化类型以消除任何歧义,但不会对可打字性产生不利影响;因此我们可以接受更多的程序。此外,我们已经证明这种简化是有效的(约束数量线性)并且是连贯的:虽然我们的算法会引发特定的重写,但所有相关的重写将具有相同的语义。我们已经为一种核心功能语言实现了我们的方法,并将其成功地应用于上述领域中的简单示例,这些示例在本文中用作说明。

著录项

相似文献

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

客服邮箱:kefu@zhangqiaokeyan.com

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

  • 服务号