DeepAI
Log In Sign Up

Functional Programming in Pattern-Match-Oriented Programming Style

02/14/2020
by   Satoshi Egi, et al.
0

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.

READ FULL TEXT

page 7

page 11

page 14

page 15

page 17

page 29

page 30

page 31

11/12/2019

Scheme Macros for Non-linear Pattern Matching with Backtracking for Non-free Data Types

Pattern matching is an important feature of programming languages for da...
08/31/2018

Non-linear Pattern Matching with Backtracking for Non-free Data Types

Non-free data types are data types whose data have no canonical forms. F...
05/02/2017

Non-linear Associative-Commutative Many-to-One Pattern Matching with Sequence Variables

Pattern matching is a powerful tool which is part of many functional pro...
11/26/2019

GOOL: A Generic Object-Oriented Language (extended version)

We present GOOL, a Generic Object-Oriented Language. It demonstrates tha...
09/22/2020

Research Summary on Implementing Functional Patterns by Synthesizing Inverse Functions

In this research summary we present our recent work on implementing func...
11/07/2018

Unification in Matching Logic

Matching Logic is a framework for specifying programming language semant...