Pattern-Matching

A term used to describe a family of programs operating over compound, structured data, usually trees or graphs. Pattern matching programs verify whether a data item complies with a pattern, i.e. an abstract structural description, and usually bind one or more variables with points in the data structure. Bindings are specified in the pattern.

Adapted and extended from FOLDOC's definition:

A function is defined to take arguments of a particular type, form or value. When applying the function to its actual arguments it is necessary to match the type, form or value of the actual arguments against the formal arguments in some definition. For example, the function:

length [] = 0 length (x:xs) = 1 + length xs

uses pattern matching in its argument to distinguish a null list from a non-null one.

There are well known algorithm for translating pattern matching into conditional expressions such as if or case. E.g. the above function could be transformed to

length l = case l of [] -> 0 x:xs -> 1 : length xs

Pattern matching is usually performed in textual order though there are languages which match more specific patterns before less specific ones.

The Tunes correspondent to this can be more general, in that specification of a non-deterministic or partially-deterministic order of traversal of function definitions can be given. The fact that code can be specified in a non-linear shape contributes to making this possible, as well as reflective specification of the traversal order.


This page is linked from: Alan Bundy   Bla   C++   CLiki Bugs   Dispatch   fare-matcher   Forklift   Godiva   Linda   ML   Moby   Qi   Scala   Sheep   TXL   Unification