Haskell Language Common GHC Language Extensions TupleSections

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

A syntactic extension that allows applying the tuple constructor (which is an operator) in a section way:

(a,b) == (,) a b

-- With TupleSections
(a,b) == (,) a b == (a,) b == (,b) a

N-tuples

It also works for tuples with arity greater than two

(,2,) 1 3 == (1,2,3)

Mapping

This can be useful in other places where sections are used:

map (,"tag") [1,2,3] == [(1,"tag"), (2, "tag"), (3, "tag")]

The above example without this extension would look like this:

map (\a -> (a, "tag")) [1,2,3]


Got any Haskell Language Question?