Haskell Language Pattern Match on Tuples


Example

Pattern matching on tuples uses the tuple constructors. To match a pair for example, we'd use the (,) constructor:

myFunction1 (a, b) = ...

We use more commas to match tuples with more components:

myFunction2 (a, b, c) = ...

myFunction3 (a, b, c, d) = ...

Tuple patterns can contain complex patterns such as list patterns or more tuple patterns.

myFunction4 ([a, b, c], d, e) = ...

myFunction5 (a, (b, (c, d), e), f) = ...