View pattern in expression context [GHC-66228]
A view pattern allows pattern matching on the result of a function. 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. This means that using them where an expression is expected is an error.
NotLambda.hs:3:9: error: [GHC-66228] View pattern in expression context: x -> x | 3 | five = (x -> x) 5 | ^^^^^^
In this example, the programmer forgot the
\ at the beginning of their anonymous function.
This caused the parser to recognize the function as a view pattern instead of a lambda.
module NotLambda where five = (x -> x) 5
module NotLambda where five = (\x -> x) 5
View pattern in expression
ViewPatternExpr.hs:3:6: error: [GHC-66228] View pattern in expression context: sqrt -> y | 3 | h = (sqrt -> y) | ^^^^^^^^^
In this context, the view pattern is being used instead of a function. The issue can be corrected by not using a view pattern.
module ViewPatternExpr where h = (sqrt -> y)
module ViewPatternExpr where h = sqrt