Tuple section in pattern [GHC-09646]

Tuple sections are a concise syntax for functions that result in tuples. The missing expressions in the tuple become arguments to the function. Because tuple sections always result in functions, and functions cannot be matched in patterns, tuple sections are not allowed in patterns.

Example Text

Tuple section in pattern context

Examples

Using tuple section in pattern

When pattern matching, tuple sections are not allowed as patterns to be matched against. In the example below, one of the components of a tuple pattern was forgotten. We can fix this by adding the wildcard _ to match on the first element of the pair.

Error Message

before.hs:4:6: error: [GHC-09646] Tuple section in pattern context
  |
4 | snd' (,x) = x 
  |      ^^^^
Failed, no modules loaded.
Snd.hs
Before
module Snd where

{-# LANGUAGE TupleSections #-}

snd' :: (a, a) -> a 
snd' (,x) = x 
After
module Snd where

{-# LANGUAGE TupleSections #-}

snd' :: (a, a) -> a 
snd' (_,x) = x