Tuple Patterns
We can think of a tuple pattern as a tuple of lower-level patterns – the lower-level patterns match individual elements in the tuple. That tuple of patterns itself makes a full pattern that matches any tuple with the same length and whose elements match the internal patterns. We could use tuple patterns for functions that return the suit and the rank of a playing card represented by a tuple:
We check that the tuple passed in is of arity two, and then return the first or second element depending on what we want to get.
Last updated