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

线性Haskell:高阶多态语言中的实用线性

Linear Haskell: practical linearity in a higher-order polymorphic language

Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, Arnaud Spiwack

摘要:

线性类型系统有着悠久的历史,但与现有语言(如OCaml或Haskell)集成的道路并不清晰。在本文中,我们研究了一个线性类型系统设计的两个关键属性:向后兼容性和代码重用的线性和非线性用户的图书馆。只有这样,线性类型的好处才能渗透到传统的函数式编程中。我们没有将类型分为线性和非线性对应物,而是将线性附加到函数箭头上。线性函数可以从线性绑定值接收输入,但也可以对不受限制的常规值进行操作。为了证明我们的线性类型系统的有效性--它可以多么容易地集成到现有的语言实现中,以及它如何简化使用线性类型编写程序--我们在领先的Haskell编译器GHC中实现了我们的类型系统,并演示了线性类型的两种应用:纯接口的可变数据;以及在I/O执行函数中执行协议。

英文摘要:

Linear type systems have a long and storied history, but not a clear path forward to integrate with existing languages such as OCaml or Haskell. In this paper, we study a linear type system designed with two crucial properties in mind: backwards-compatibility and code reuse across linear and non-linear users of a library. Only then can the benefits of linear types permeate conventional functional programming. Rather than bifurcate types into linear and non-linear counterparts, we instead attach linearity to function arrows. Linear functions can receive inputs from linearly-bound values, but can also operate over unrestricted, regular values. To demonstrate the efficacy of our linear type system - both how easy it can be integrated in an existing language implementation and how streamlined it makes it to write programs with linear types - we implemented our type system in GHC, the leading Haskell compiler, and demonstrate two kinds of applications of linear types: mutable data with pure interfaces; and enforcing protocols in I/O-performing functions.

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

↑