Skip to content

Commit 94e03ad

Browse files
authored
Merge pull request #423 from TauOmicronMu/main
Add docs for GHC-04584
2 parents 6a7fb33 + aba242f commit 94e03ad

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Expression syntax in pattern
3+
summary: There has been an attempt to pattern match on expression syntax.
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+
Expression syntax in pattern: [1 .. 10]
14+
```
15+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Matchingdots where
2+
3+
-- If the input is [1..10], return 0, otherwise return 1
4+
f :: [Int] -> Int
5+
f xs
6+
| xs == [1..10] = 0
7+
| otherwise = 1
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Matchingdots where
2+
3+
-- If the input is [1..10], return 0, otherwise return 1
4+
f :: [Int] -> Int
5+
f [1..10] = 0
6+
f _ = 1
7+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Using .. in pattern
3+
---
4+
5+
When pattern matching, expressions are not allowed as patterns to be matched against. Instead, consider matching on a list, and using a conditional.
6+
7+
8+
# Error Message
9+
10+
```
11+
before_dots.hs:3:3: error: [GHC-04584]
12+
Expression syntax in pattern: [1 .. 10]
13+
|
14+
3 | f [1..10] = 0
15+
| ^^^^^^^
16+
```

0 commit comments

Comments
 (0)