Pattern matching: Difference between revisions

Content deleted Content added
Zemiak123 (talk | contribs)
m wikilink
Line 1:
{{aboutAbout|pattern matching in [[functional programming]]||string matching|and|pattern recognition}}
{{forFor|the use of variable matching criteria in defining abstract patterns to match|regular expression}}
{{RefimproveMore citations needed|date=February 2011}}
In [[computer science]], '''pattern matching''' is the act of checking a given '''sequence''' of [[Lexical analysis#Token|tokens]] for the presence of the constituents of some [[pattern]]. In contrast to [[pattern recognition]], the match usually has to be exact: "either it will or will not be a match." The patterns generally have the form of either [[string (computer science)|sequences]] or [[tree structure]]s. Uses of pattern matching include outputting the locations (if any) of a pattern within a token sequence, to output some component of the matched pattern, and to substitute the matching pattern with some other token sequence (i.e., [[Regular expression|search and replace]]).
 
Line 64:
The creations of these functions can be automated by Haskell's data [[Record (computer science)|record]] syntax.
 
This [[Ocaml]] example which defines a [[Red–black_treeRed–black tree|red-black tree]] and a function to re-balance it after element insertion shows how to match on a more complex structure generated by a recursive data type.
 
<syntaxhighlight lang="ocaml">
Line 250:
 
==External links==
{{wikibooksWikibooks|Haskell|Pattern matching}}
{{Commons category}}
{{Commonscat}}
*[http://www.haskell.org/tutorial/patterns.html A Gentle Introduction to Haskell: Patterns]
*[https://archive.is/19990225161739/http://www.haskell.org/development/views.html Views: An Extension to Haskell Pattern Matching]
Line 267:
 
{{Strings |state=collapsed}}
{{Authority control}}
 
{{DEFAULTSORT:Pattern Matching}}