Pattern calculus
{{More footnotes|date=November 2016}}
Pattern calculus bases all computation on pattern matching of a very general kind. Like lambda calculus, it supports a
uniform treatment of function evaluation. Also, it allows functions to be
passed as arguments and returned as results. In addition, pattern calculus supports
uniform access to the internal structure of arguments, be they pairs
or lists or trees. Also, it allows patterns to be passed as arguments and
returned as results. Uniform access is illustrated by a
pattern-matching function {{code|size}} that computes the size of an
arbitrary data structure. In the notation of the programming language
bondi, it is given by the recursive function
| x y -> (size x) + (size y)
| x -> 1
The second, or default case {{code|x -> 1}} matches the pattern {{code|x}}
against the argument and returns {{code|1}}. This
case is used only if the matching failed in the first case. The
first, or special case matches against any compound, such
as a non-empty list, or pair. Matching binds {{code|x}} to the left component
and {{code|y}} to the right component. Then the body of the case adds the
sizes of these components together.
Similar techniques yield generic queries for searching and updating. Combining recursion and decomposition in this way yields path polymorphism.
The ability to pass patterns as parameters (pattern polymorphism) is illustrated by defining a
generic eliminator. Suppose given constructors {{code|Leaf}} for creating
the leaves of a tree, and {{code|Count}} for converting numbers into
counters. The corresponding eliminators are then
elimLeaf = | Leaf y -> y
elimCount = | Count y -> y
For example, {{code|elimLeaf (Leaf 3)}} evaluates to {{code|3}} as does {{code|elimCount (Count 3)}}.
These examples can be produced by applying the generic eliminator
{{code|elim}} to the constructors in question. It is defined by
elim = | x -> | {y} x y -> y
Now {{code|elim Leaf}} evaluates to | {y} Leaf y -> y
which is equivalent to {{code|elimLeaf}}. Also {{code|elim Count}} is equivalent to {{code|elimCount}}.
In general, the curly braces {{code|{} }} contain the bound variables of the
pattern, so that {{code|x}} is free and {{code|y}} is bound in | {y} x y -> y
.
External links
{{refbegin}}
- [https://web.archive.org/web/20120327091406/http://www-staff.it.uts.edu.au/~cbj/patterns/ Archive mirror of the links below (which are no longer online)]
- {{cite journal |first=C. Barry |last=Jay |title=The pattern calculus |journal=ACM Trans. Program. Lang. Syst. |volume=26 |issue=6 |pages= 911–937|date=November 2004 |doi=10.1145/1034774.1034775 |s2cid=14252624 |doi-access=free }} — the original paper, but not most general.
- {{cite book |last1=Jay |first1=B. |last2=Kesner |first2=D. |chapter=Pure Pattern Calculus |doi=10.1007/11693024_8 |editor-last=Sestoft |editor-first=P. |title=Programming Languages and Systems. ESOP 2006 |publisher=Springer |series=Lecture Notes in Computer Science |volume=3924 |date=2006 |isbn=978-3-540-33096-7 |pages=100–114 |hdl=10453/1684}}
- {{cite book |first=Barry |last=Jay |title=Pattern Calculus: Computing with Functions and Structures |publisher=Springer |date=2009 |doi=10.1007/978-3-540-89185-7 |isbn=978-3-540-89185-7 |pages= |url=https://link.springer.com/book/10.1007/978-3-540-89185-7}}
- [http://bondi.it.uts.edu.au/ bondi programming language research site]
- {{cite book |last1=Given-Wilson |first1=T. |last2=Gorla |first2=D. |last3=Jay |first3=B. |chapter=Concurrent Pattern Calculus |editor1-last=Calude |editor1-first=C.S. |editor2-last=Sassone |editor2-first=V. |title=Theoretical Computer Science. TCS 2010 |publisher=Springer |series=IFIP Advances in Information and Communication Technology |volume=323 |date=2010 |isbn=978-3-642-15240-5 |url= |doi=10.1007/978-3-642-15240-5_18}}
{{refend}}