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

懒惰语言需要懒惰类型系统:引入多态上下文

A Lazy Language Needs a Lazy Type System: Introducing Polymorphic Contexts

S. Doaitse Swierstra, Marcos Viera, Atze Dijkstra

摘要:

大多数支持多态函数的类型系统都基于System-F的某个版本。我们认为,这限制了有用的编程范例的语言与懒惰的评价。我们激励系统F的扩展,减轻这种限制。首先,使用一系列的例子,我们表明,懒惰评估的语言,目前的类型系统可能会迫使一个写一个程序在一个不自然的方式,我们特别认为,在这样的语言之间的关系多态和存在类型可以更系统地允许传递回(部分)的存在结果的函数调用作为参数的函数调用,产生该值。在介绍了我们对System-F的扩展之后,我们展示了如何通过在专门化返回该类型的多态函数中使用返回的存在类型来实现严格状态线程monad $\mathrm{ST}$。目前,这个monad内置在GHC的运行时系统中,因此已经成为语言的一部分。我们提出的语言扩展,即多态上下文的引入,颠倒了函数调用的上下文和被调用的函数之间的关系,关于在哪里决定用哪种类型来实例化类型变量。

英文摘要:

Most type systems that support polymorphic functions are based on a version of System-F. We argue that this limits useful programming paradigms for languages with lazy evaluation. We motivate an extension of System-F alleviating this limitation. First, using a sequence of examples, we show that for lazily evaluated languages current type systems may force one to write a program in an unnatural way; we in particular argue that in such languages the relationship between polymorphic and existential types can be made more systematic by allowing to pass back (part of) an existential result of a function call as an argument to the the function call that produced that value. After presenting our extension to System-F we show how we can implement the strict-state thread monad $\mathrm{ST}$ by using a returned existential type in specialising the polymorphic function which returns that type. Currently this monad is built-in into the runtime system of GHC and as such has become part of the language. Our proposed language extension, i.e. the introduction of polymorphic contexts, reverses the relationship between the context of a function call and the called function with respect to where it is decided with which type to instantiate a type variable.

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

↑