Skip to content

Commit 6a7fb33

Browse files
Merge pull request #426 from TauOmicronMu/09646
Add docs for GHC-09646
2 parents e20de0f + 426e88d commit 6a7fb33

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Tuple section in pattern
3+
summary: There has been an attempt to pattern match on a tuple section.
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
[Tuple sections](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/tuple_sections.html) 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.
9+
10+
## Example Text
11+
12+
```
13+
Tuple section in pattern context
14+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Snd where
2+
3+
{-# LANGUAGE TupleSections #-}
4+
5+
snd' :: (a, a) -> a
6+
snd' (_,x) = x
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Snd where
2+
3+
{-# LANGUAGE TupleSections #-}
4+
5+
snd' :: (a, a) -> a
6+
snd' (,x) = x
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Using tuple section in pattern
3+
---
4+
5+
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.
6+
7+
# Error Message
8+
9+
```
10+
before.hs:4:6: error: [GHC-09646] Tuple section in pattern context
11+
|
12+
4 | snd' (,x) = x
13+
| ^^^^
14+
Failed, no modules loaded.
15+
```

0 commit comments

Comments
 (0)