论文标题

以图案为导向的编程样式的功能编程

Functional Programming in Pattern-Match-Oriented Programming Style

论文作者

Egi, Satoshi, Nishiwaki, Yuichi

论文摘要

在整个功能编程的历史中,递归已成为描述程序中循环的一种自然方法。但是,即使对于基本列表处理功能,例如MAP,CONCAT或唯一的算法,递归定义与最简单的解释之间通常确实存在实质性的认知距离;当我们解释这些功能时,我们很少像在功能编程中那样明确使用递归。例如,通常将MAP解释如下:MAP功能获取功能和列表,并返回将函数应用于列表的所有元素的结果列表。 本文提倡一个新的编程范式,称为“图案匹配”编程,用于填补此空白。我们方法的基本要素是利用非免费数据类型的模式匹配。非免费数据类型的模式匹配具有非线性模式与回溯和图案匹配算法的可扩展性匹配。几种非标准的模式构建体,例如非模式,循环模式和顺序模式,源自此模式匹配设施。基于这一结果,本文介绍了许多编程技术,这些技术通过将递归限制在模式内部的递归中,以直观的模式代替显式递归。我们将这些技术归类为面向模式的编程设计模式。 这些编程技术使我们不仅可以比传统的功能编程样式更优雅地定义列表处理的最基本功能,而且还可以重新定义更实用的数学算法和软件,例如SAT求解器,计算机代数系统和数据库查询语言,而我们无法精心实现。

Throughout the history of functional programming, recursion has emerged as a natural method for describing loops in programs. However, there does often exist a substantial cognitive distance between the recursive definition and the simplest explanation of an algorithm even for the basic list processing functions such as map, concat, or unique; when we explain these functions, we seldom use recursion explicitly as we do in functional programming. For example, map is often explained as follows: the map function takes a function and a list and returns a list of the results of applying the function to all the elements of the list. This paper advocates a new programming paradigm called pattern-match-oriented programming for filling this gap. An essential ingredient of our method is utilizing pattern matching for non-free data types. Pattern matching for non-free data types features non-linear pattern matching with backtracking and extensibility of pattern-matching algorithms. Several non-standard pattern constructs, such as not-patterns, loop patterns, and sequential patterns, are derived from this pattern-matching facility. Based on that result, this paper introduces many programming techniques that replace explicit recursions with an intuitive pattern by confining recursions inside patterns. We classify these techniques as pattern-match-oriented programming design patterns. These programming techniques allow us to redefine not only the most basic functions for list processing such as map, concat, or unique more elegantly than the traditional functional programming style, but also more practical mathematical algorithms and software such as a SAT solver, computer algebra system, and database query language that we had not been able to implement concisely.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源