Haskell Language Tuples (Pairs, Triples, ...) Swap pair components


Example

Use swap (from Data.Tuple) to swap the components of a pair.

import Data.Tuple (swap)
swap (1, 2) -- evaluates to (2, 1)

Or use pattern matching.

case (1, 2) of (x, y) => (y, x) -- evaluates to (2, 1)