GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2023-11-28T14:55:55Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/24226Function type mistaken for ViewPatterns in T2T VDQ2023-11-28T14:55:55ZArtin Ghasivandghasivand.artin@gmail.comFunction type mistaken for ViewPatterns in T2T VDQPassing 'function type\` arguments to VDQ functions, without the `type` keyword, causes GHC to get confused, and think it's a view pattern.
Example (`card` is defined in #24225):
```haskell
t1 = card (type (Bool -> Bool)) -- Fine
-- F...Passing 'function type\` arguments to VDQ functions, without the `type` keyword, causes GHC to get confused, and think it's a view pattern.
Example (`card` is defined in #24225):
```haskell
t1 = card (type (Bool -> Bool)) -- Fine
-- Fails and triggers the error message below
t2 = card (Bool -> Bool)
{-
src/VDQ.hs:71:11-22: error: [GHC-66228] …
View pattern in expression context: Bool -> Bool
|
Compilation failed.
-}
```
GHC version: 9.9.20231126Vladislav ZavialovVladislav Zavialovhttps://gitlab.haskell.org/ghc/ghc/-/issues/22406Inaccessible binding in the same decl group is suggested in view pattern2023-07-20T16:17:11ZTorsten SchmitsInaccessible binding in the same decl group is suggested in view pattern## Summary
GHC suggests to use an existing function with matching name in a view pattern, even though it is not in scope.
## Steps to reproduce
```haskell
(v -> _) = undefined
v = undefined
-- • Variable not in scope: v :: t0 -> t1
--...## Summary
GHC suggests to use an existing function with matching name in a view pattern, even though it is not in scope.
## Steps to reproduce
```haskell
(v -> _) = undefined
v = undefined
-- • Variable not in scope: v :: t0 -> t1
-- • Perhaps you meant ‘v’
```
## Expected behavior
GHC does not suggest to use `v`https://gitlab.haskell.org/ghc/ghc/-/issues/17098Document how to write a pattern synonym that uses a view pattern2021-01-22T23:50:33ZSimon JakobiDocument how to write a pattern synonym that uses a view patternIt took me a bit to figure out how to apply a function to the expression that I want to pattern match on – turns out you can use `ViewPatterns`, as for example `containers`' `Seq` does:
```
pattern (:<|) :: a -> Seq a -> Seq a
pattern x...It took me a bit to figure out how to apply a function to the expression that I want to pattern match on – turns out you can use `ViewPatterns`, as for example `containers`' `Seq` does:
```
pattern (:<|) :: a -> Seq a -> Seq a
pattern x :<| xs <- (viewl -> x :< xs)
where
x :<| xs = x <| xs
```
I think this should be documented in [the user's guide](https://gitlab.haskell.org/ghc/ghc/blob/5e40356f65bc2d62c73be8015c759899f072ac9a/docs/users_guide/glasgow_exts.rst#L5433).9.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/14293View patterns with locally defined functions in restructuring don't compile2023-01-19T12:51:24ZGabor GreifView patterns with locally defined functions in restructuring don't compile```hs
{-# LANGUAGE ViewPatterns #-}
foo x = x
Just (id -> res) = pure 'a' -- WORKS
Just (foo -> res') = pure 'a' -- FAILS
bar (foo -> res) = res -- WORKS
{-
[1 of 1] Compiling Main ( T14293.hs, interpreted )
T1...```hs
{-# LANGUAGE ViewPatterns #-}
foo x = x
Just (id -> res) = pure 'a' -- WORKS
Just (foo -> res') = pure 'a' -- FAILS
bar (foo -> res) = res -- WORKS
{-
[1 of 1] Compiling Main ( T14293.hs, interpreted )
T14293.hs:6:7-9: error: Variable not in scope: foo :: Char -> t
|
6 | Just (foo -> res') = pure 'a'
| ^^^
Failed, 0 modules loaded.
-}
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.2.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"View patterns with locally defined functions in restructuring don't compile","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{#!hs\r\n{-# LANGUAGE ViewPatterns #-}\r\n\r\nfoo x = x\r\n\r\nJust (id -> res) = pure 'a' -- WORKS\r\nJust (foo -> res') = pure 'a' -- FAILS\r\nbar (foo -> res) = res -- WORKS\r\n\r\n\r\n{-\r\n\r\n[1 of 1] Compiling Main ( T14293.hs, interpreted )\r\n\r\nT14293.hs:6:7-9: error: Variable not in scope: foo :: Char -> t\r\n |\r\n6 | Just (foo -> res') = pure 'a'\r\n | ^^^\r\nFailed, 0 modules loaded.\r\n\r\n-}\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/14133COMPLETE pragmas seem to be ignored when using view patterns2023-07-31T10:31:19ZjleCOMPLETE pragmas seem to be ignored when using view patterns```hs
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
pattern I :: Int -> Int
pattern I x <- (id -> x)
{-# COMPLETE I #-}
foo :: Int -> Int
foo (I x) = x + 3
bar :: Int -> Int
bar (id->I x) = x + 3
main :: IO ()
main =...```hs
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
pattern I :: Int -> Int
pattern I x <- (id -> x)
{-# COMPLETE I #-}
foo :: Int -> Int
foo (I x) = x + 3
bar :: Int -> Int
bar (id->I x) = x + 3
main :: IO ()
main = return ()
```
Raises a warning for `bar`:
```
Bug.hs:12:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for 'bar': Patterns not matched: _
|
12 | bar (id->I x) = x + 3
| ^^^^^^^^^^^^^^^^^^^^^^^
```
but not for `foo`.