Skip to content

Commit 346a33d

Browse files
Merge pull request #344 from haskellfoundation/GHC-66228
Document GHC-66228
2 parents d50f433 + f5fa782 commit 346a33d

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: View pattern in expression context
3+
summary: A view pattern was used in an expression, rather than a pattern.
4+
extension: ViewPatterns
5+
introduced: 9.6.1
6+
---
7+
8+
A [view pattern](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/view_patterns.html) allows pattern matching on the result of a function.
9+
While most kinds of patterns look just like the expressions that construct the data that the pattern recognizes, view patterns don't correspond directly to an expression.
10+
This means that using them where an expression is expected is an error.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module NotLambda where
2+
3+
five = (\x -> x) 5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module NotLambda where
2+
3+
five = (x -> x) 5
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Missing lambda
3+
---
4+
## Message
5+
```
6+
NotLambda.hs:3:9: error: [GHC-66228]
7+
View pattern in expression context: x -> x
8+
|
9+
3 | five = (x -> x) 5
10+
| ^^^^^^
11+
```
12+
13+
## Explanation
14+
15+
In this example, the programmer forgot the `\` at the beginning of their anonymous function.
16+
This caused the parser to recognize the function as a view pattern instead of a lambda.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module ViewPatternExpr where
2+
3+
h = sqrt
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module ViewPatternExpr where
2+
3+
h = (sqrt -> y)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: View pattern in expression
3+
---
4+
## Message
5+
```
6+
ViewPatternExpr.hs:3:6: error: [GHC-66228]
7+
View pattern in expression context: sqrt -> y
8+
|
9+
3 | h = (sqrt -> y)
10+
| ^^^^^^^^^
11+
```
12+
13+
## Explanation
14+
15+
In this context, the view pattern is being used instead of a function.
16+
The issue can be corrected by not using a view pattern.

0 commit comments

Comments
 (0)