Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Pattern Matching

< >
Example from Haskell:
fib 0 = 1 fib 1 = 1 fib n | n >= 2 = fib (n-1) + fib (n-2)
Example from Elixir:
def fib(0), do: 1 def fib(1), do: 1 def fib(n) when n >= 2, do: fib(n-1) + fib(n-2)
Example from Coconut:
match [head] + tail in [0, 1, 2, 3]: print(head, tail)
Example from Felix:
match x with | Some x => println$ x; | None => println "NONE"; endmatch;

Languages with Pattern Matching include Rust, Haskell, Elixir, Coconut, HOPE, Felix, NPL

Languages without Pattern Matching include progsbase

Our definition

In computer science, pattern matching is the act of checking a given sequence of 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 sequences or tree structures. 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., search and replace). Read more on Wikipedia...

partial-application.html 路 pattern-matching.html 路 pipes.html

View source

PLDB - Build the next great programming language 路 v2023 Day 141 Docs Build Acknowledgements Traffic Today Traffic Trends Mirrors GitHub