【24h】

A New Approach to Generic Functional Programming

机译:泛型函数编程的新方法

获取原文

摘要

This paper describes a new approach to generic functional programming, which allows us to define functions generically for all datatypes expressible in Haskell. A generic function is one that is defined by induction on the structure of types. Typical examples include pretty printers, parsers, and comparison functions. The advanced type system of Haskell presents a real challenge: datatypes may be parameterized not only by types but also by type constructors, type definitions may involve mutual recursion, and recursive calls of type constructors can be arbitrarily nested. We show thatdespite this complexitya generic function is uniquely defined by giving cases for primitive types and type constructors (Such as disjoint unions and cartesian products). Given this information a generic function can be specialized to arbitrary Haskell datatypes. The key idea of the approach is to model types by terms of the simply typed #lambda#-calculus augmented by a family of recursion operators. While conceptually simple, our approach places high demands on the type system: it requires polymorphic recursion, rank-n types, and a strong form of type constructor polymorphism. Finally, we point out connections to Haskell's class system and show that our approach generalizes type classes in some respects.
机译:本文介绍了一种通用函数编程的新方法,该方法使我们能够为Haskell中可表达的所有数据类型通用地定义函数。泛型函数是通过归纳类型结构定义的函数。典型示例包括漂亮的打印机,解析器和比较功能。 Haskell的高级类型系统提出了一个真正的挑战:数据类型不仅可以通过类型而且可以通过类型构造函数进行参数化,类型定义可能涉及相互递归,并且可以任意嵌套嵌套类型构造函数的递归调用。我们显示,尽管复杂性高,但泛型函数是通过为原始类型和类型构造函数(例如不相交联合和笛卡尔积)提供用例来唯一定义的。给定此信息,通用函数可以专用于任意Haskell数据类型。该方法的关键思想是根据一系列递归运算符扩充的简单类型的#lambda#-演算来对类型进行建模。尽管从概念上讲很简单,但是我们的方法对类型系统提出了很高的要求:它需要多态递归,rank-n类型以及类型构造函数多态的强形式。最后,我们指出了与Haskell的类系统的联系,并表明我们的方法在某些方面概括了类型类。

著录项

相似文献

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

客服邮箱:kefu@zhangqiaokeyan.com

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

  • 服务号