Relevant For...

While programming, it is often useful to match expressions that have a particular form, like sequences or tree structures, rather than laboriously parse them out with conditionals. The purpose of pattern matching is to match expressions with patterns and bind variables to successful matches. For example, if we have a list processing function, rather than explicitly test for the existence of a head and tail, then explicitly access the head and tail, we can simply ask if the input list has the pattern of a list with a head and tail, and if so, immediately use the bound values for computation. Pattern matching has not yet been widely adopted, but is especially useful in modern functional languages like OCaml, Haskell, F#, and Mathematica, among others.

The basic idea is to apply the function on the first element and attach it to the map of the rest of the list. Of course, you have to tell that the map of the empty list is just the empty list, whatever be the function.

Tuples

Pattern matching inside tuples sure would work.

The following function calculates the distance between two points on a plane.

1

distance(x1,y1)(x2,y2)=sqrt((x1-x2)^2+(y1-y2)^2)

Other Data Types

Haskell supports algebraic data types. Since they are constructed through functors, pattern matching would work in a similar way.