Description
It seems that the suggested pattern signature is not always correct in the presence of provided constraints. For instance:
{-# LANGUAGE PatternSynonyms #-}
import GHC.TypeNats
pattern MySomeNat a = SomeNat a
HLS suggests the pattern signature
pattern MySomeNat :: KnownNat n => Proxy n -> SomeNat
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:
pattern MySomeNat :: () => KnownNat n => Proxy n -> SomeNat
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:
class MyClass (n :: Nat)
pattern MySomeNat1 :: MyClass n => KnownNat n => Proxy n -> SomeNat
pattern MySomeNat1 a = SomeNat a
pattern MySomeNat2 a = MySomeNat1 a
HLS suggests the pattern signature:
pattern MySomeNat2 :: (MyClass n, KnownNat n) => Proxy n -> SomeNat
Not understanding that
pattern MySomeNat2 :: MyClass n => KnownNat n => Proxy n -> SomeNat
means something different.
It seems like there is some logic that rewrites a constraint involving multiple constraint arrows. For instance, if one writes:
{-# LANGUAGE NoMonomorphismRestriction #-}
x :: () => Num a => Ord a => Bounded a => a
x = 1
y = x
Then HLS suggests the following type for y:
y :: (Num a, Ord a, Bounded a) => a
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.