-
-
Notifications
You must be signed in to change notification settings - Fork 389
Suggested pattern signature doesn't account for provided constraints #1975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Duplicate of #1951; should be fixed by #1952. This is from a unit test in that PR. I think this covers the use case you have in mind? ghcide/test/Main.hs data T1 a where
MkT1 :: (Show b) => a -> b -> T1 a
pattern MkT1' b = MkT1 42 b
-- And we test that we get this type suggested
-- pattern MkT1' :: (Eq a, Num a) => Show b => b -> T1 a" Hmm, can you confirm something for me? I think the types here are correct: data T1 a where
MkT1 :: (Show b) => a -> b -> T1 a
pattern MkT1' :: (Eq a, Num a) => Show b => b -> T1 a
pattern MkT1' b = MkT1 42 b
y :: (Eq a, Num a, Show b) => b -> T1 a
y x = MkT1' x y uses MkT1' as an expression and so calling y requires Show b. |
@sheaf thanks for report the issue, will close as duplicate if you use case match the test posted above |
Excellent, thanks for your work @peterwicksstringfield. Your solution does indeed cover the situation in the OP. To answer your other question, in your second example, the type signature you give for |
@sheaf, thanks! Glad we are on the same page. |
It seems that the suggested pattern signature is not always correct in the presence of provided constraints. For instance:
HLS suggests the pattern signature
which is incorrect, as
KnownNat n
is not a required constraint (that is needed in order to write down the pattern synonym) but a provided one (which becomes available once pattern matching succeeds).The pattern signature that HLS should suggest is the following:
which uses the peculiar pattern signature syntax wherein the first set of constraints denotes those that are required, and the second the provided ones.
Another example:
HLS suggests the pattern signature:
Not understanding that
means something different.
It seems like there is some logic that rewrites a constraint involving multiple constraint arrows. For instance, if one writes:
Then HLS suggests the following type for y:
This is obviously fine in this case, but the same rewriting is invalid for pattern signatures.
Version: Haskell Language Server 1.2.0 with GHC 9.0.
The text was updated successfully, but these errors were encountered: