Skip to content

Commit 5fb1c4e

Browse files
committed
Add docs for GH-09646
1 parent e36ca33 commit 5fb1c4e

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+
Pattern matching allows constructors and literals to be used to take apart values, exposing their contents. The syntax of patterns is very similar to that of the expressions that create values, but many constructs that are allowed in expression contexts are not meaningful 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, 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)